cnpm nrm yarn 淘宝镜像切换

本文详细介绍了解决npm安装依赖速度慢的问题,提供了使用nrm工具切换镜像源的步骤,包括安装、测试、更换及删除源的方法,并介绍了如何使用cnpm和yarn加速npm包的下载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

使用 npm install 命令,下载相关依赖库,但是由于网络原因,下载速度快

解决办法

切换镜像,从npm 默认镜像https://registry.npmjs.org/改为国内的

更换安装源

nrm(npm registry manager )是npm的镜像源管理工具,有时候国外资源太慢,使用这个就可以快速地在 npm 源间切换

安装nrm

npm install nrm --global

查看可以使用的安装源

	nrm ls

结果

* npm -------- https://registry.npmjs.org/
  yarn ------- https://registry.yarnpkg.com/
  cnpm ------- http://r.cnpmjs.org/
  taobao ----- https://registry.npmmirror.com/
  nj --------- https://registry.nodejitsu.com/
  npmMirror -- https://skimdb.npmjs.com/registry/
  edunpm ----- http://registry.enpmjs.org/

测试源(看哪个源的速度最快)

	nrm test

结果

* npm ---- 1195ms
  yarn --- 2936ms
  cnpm --- 235ms
  taobao - 224ms
  nj ----- Fetch Error
  npmMirror  6066ms
  edunpm - Fetch Error

备注: 数字越小,响应速度越快

添加一个新的源

nrm add newRep http://IP:端口/repository/npm-public/

newRep 是添加源的名字,类似于 “taobao”一样

更换源

nrm use taobao
  1. 使用 npm config list 命令,可以查看到 registry = "https://registry.npmjs.org/"
  2. 执行 nrm use taobao
  3. 使用 npm config list 命令,可以查看到 registry = "https://registry.npmmirror.com/"

删除源

nrm del aaa

使用cnpm 或者 yarn,切换淘宝镜像

安装cnpm

npm install -g cnpm --registry=https://registry.npmmirror.com

安装yarn

cnpm install -g yarn

使用国内镜像加速npm和yarn

  1. npm config set registry=https://registry.npmmirror.com 等价于 nrm use taobao

  2. yarn config set registry https://registry.npmmirror.com

unable to verify the first certificate报错?

切换到淘宝镜像之后报如上错误,解决办法如下:

npm config set strict-ssl false

或者

yarn config set strict-ssl false
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值