配置代理
npm config set registry https://registry.npm.taobao.org/
如果用的是公司内部网络,可能需要设置代理才能正常下载:
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:8080
使用镜像
1、设置淘宝镜像源
npm config set registry https://registry.npmmirror.com/
2、设置官方镜像源
npm config set registry https://registry.npmjs.org
3.查看镜像状态
npm config get registry
使用cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com
解决安装卡顿或无法安装:
注册模块镜像
npm set registry https://registry.npmmirror.com
// node-gyp 编译依赖的 node 源码镜像
npm set disturl https://npmmirror.com/dist
// 清空缓存
npm cache clean --force
// 安装cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com