文章目录
问题描述
使用 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
- 使用
npm config list
命令,可以查看到registry = "https://registry.npmjs.org/"
- 执行
nrm use taobao
- 使用
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
-
npm config set registry=https://registry.npmmirror.com
等价于nrm use taobao
-
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