npm install 无响应解决方案

方案一:使用cnpm

安装:

npm install cnpm -g

或许你在中国,那么你可以能需要使用这个源:淘宝NPM镜像

npm install cnpm -g --registry=https://registry.npm.taobao.org

安装模块

从registry.npm.taobao.org安装的所有模块,当安装的时候发现安装的模块还没有同步过来,淘宝NPM会自动在后台进行同步,并且会让你从官方NPM 进行安装。下次你再安装这个模块的时候,就会直接从淘宝 NPM 安装了。

cnpm install [name]

同步模块

cnpm sync [moduleName]

注意:cnpm支持npm除了publish之外的所有命令 ,也就是不支持publish,当然这并不影响我们使用,publish时换回npm即可。

方案二:使用smart-npm

用npm时,默认他会访问国外的资源,所以会非常卡,有时甚至会被墙。现在市面上一般有三种解决方案:

  1. 在.npmrc上配置一个国内的registry镜像。
  2. 使用cnpm。
  3. 使用VPN

方案一,很粗暴,可以解决很多下载慢的问题,但是当你用npm publish时就会失败

方案二,不错,但这样又会遇到问题 ,到底哪些命令需要用cnpm哪些命令需要用npm呢?

方案三,有时也不能百分百解决问题,有时有些VPN也不稳定,但有个VPN很保险就是。

其实cnpm的意图并不是简单给我们用来去下载的npm资源的,他是为cnpm服务端服务的。

所以,我们就需要一个更智能的npm了,可以在我们使用npm install 时自动从国内的镜像下载,而在我们使用npm publish 又能发布到官方的registry上。

这样就让 smart-npm来完成吧!

安装

npm install --global smart-npm --registry=https://registry.npm.taobao.org/

如果window用户安装最新版本不成功的话,可以试试安装smart-npm@1

npm install --global smart-npm@1 --registry=https://registry.npm.taobao.org/

安装成功后默认会在你的npm用户配置文件 ~/.npmrc中添加淘宝的registry。

卸载:

npm smart uninstall   # 2.x.x 版本的 smart-npm 在卸载前需要先执行此脚本
npm uninstall --global smart-npm

先执行 npm smart uninstall 是因为如果直接执行npm uninstall 会导致找不到npm文件。

使用:

  • 安装后系统的npm 会被替换了,如果你要是用原生的npm命令,可以用 npm-original 代替。
  • 新的npm 会自动根据你使用的命令切换 registry。
    • 当你使用publish、config、adduser、star、等命令式,会强制使用官方的registry
    • 当你使用其他命令时,都会使用淘宝的镜像
  • 如果要强制使用某个registry时,只要在命令后面添加 registry参数即可,例如:
    npm install jquery --registry=https://r.cnpmjs.org
    

    就会使用你指定的registry去拉取

  • 如果要强制使用官方的registry,只要在命令后面加上 --npm 即可,比如
    npm install jquery --npm
    

    就会使用官方的registry去拉取jquery

 方案三:使用nrm

nrm 是一个NPM 资源管理器

安装:

npm install -g nrm

使用:

nrm add [home]

删除源

nrm del

测试速度

nrm test

   

 备注

npm---https://registry.npmjs.org

cnpm ----  http://r.cnpmjs.org/

taobao --  https://registry.npm.taobao.org/

原文地址:https://www.cnblogs.com/Imever/p/6053932.html