npm安装下载依赖包失败的问题

使用npm下载nodejs依赖包时,会出现下载失败,可以使用如下方法解决:

1. npm默认的镜像地址为国外镜像地址

npm config get registry
# http://registry.npmjs.org 为国外镜像地址

从国外镜像地址下载依赖包时,速度很慢甚至会出现异常。因此可以将npm的镜像地址改为国内镜像,阿里镜像:https://registry.npm.taobao.org

npm config set registry https://registry.npm.taobao.org

2. 设置http代理

如果更改为国内镜像地址后,仍然下载失败。则考虑为网络问题,有可能是公司网络进行了限制,可以设置相应的http代理

 

npm ERR! network request to https://registry.npm.taobao.org/arr-diff failed, reason: connect ETIMEDOUT 122.225.34.181:443
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

出现上述错误后,可以设置http代理,如下:

npm config set https-proxy http://server:port
npm config set proxy http://server:port

注意:其中server为当前使用的代理服务器的ip   port为代理服务器的端口号

 

 


版权声明:本文为u012723673原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。