解决npm 安装部分依赖失败问题总结

  • 有时候,我们通过npm install进行项目初始化,会由于“天朝墙”的原因,可能会导致下载速度慢,无法下载等等问题出现。
    好在现在有很多国内镜像,也有一个帮助我们随意切换 npm 镜像的工具:nrm。
npm install -g nrm
nrm ls

* npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/

nrm use taobao
  • 现在我们将镜像切换成了淘宝:
 npm ---- https://registry.npmjs.org/
 cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
 nj ----- https://registry.nodejitsu.com/
 rednpm - http://registry.mirror.cqupt.edu.cn/
 npmMirror  https://skimdb.npmjs.com/registry/
 edunpm - http://registry.enpmjs.org/
  • 但是有个弊端,当项目被其他人克隆后,每个人都要进行nrm,有点麻烦,可以在根目录创建添加 .npmrc 文件:
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
electron_mirror=https://npm.taobao.org/mirrors/electron/
registry=https://registry.npm.taobao.org
  • 直接进行npm install 时,npm 都会根据跟目录下 .npmrc 中的配置进行依赖的安装。

你可能感兴趣的:(解决npm 安装部分依赖失败问题总结)