我有一个npm的问题,我不能安装任何东西。以下是错误信息:

C:\Windows\system32>npm install -g yo
npm http GET https://registry.npmjs.org/yo
npm http GET https://registry.npmjs.org/yo
npm http GET https://registry.npmjs.org/yo
npm ERR! network read ECONNRESET
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settin
gs.
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'

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "yo"
npm ERR! cwd C:\Windows\system32
npm ERR! node -v v0.10.17
npm ERR! npm -v 1.3.8
npm ERR! syscall read
npm ERR! code ECONNRESET
npm ERR! errno ECONNRESET
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Windows\system32\npm-debug.log
npm ERR! not ok code 0

知道为什么吗?这是我的网络设置,似乎我没有配置任何代理。我还关闭了所有的防火墙。


当前回答

我已经尝试了几乎所有张贴在这里和其他页面的方法,但都不工作。以下是我按顺序执行的命令,我鼓励你尝试一下,因为它对许多人都有效(但不是我):

NPM配置rm代理 NPM配置rm http -proxy NPM设置http -proxy https://username:password@proxy.company.com:6050 NPM配置代理http://username:password@proxy.company.com:6050 NPM配置设置注册表http://registry.npmjs.org/

然后尝试安装npm install -g express包,但是失败了。

然而,当我试图运行npm install npm@latest -g时,它奇迹般地执行并安装良好! 然后再次运行npm install -g express也完全正常。

TL;DR:更新npm到最新版本解决了这个问题(目前是6.0.1)

其他回答

这对我来说很管用:

proxy = http://1.1.1.1:3128/
https_proxy = http://1.1.1.1:3128/
strict-ssl = false
ca = null
registry = http://registry.npmjs.org/

答案在这里:https://fak3r.com/2015/07/31/howto-use-npm-behind-a-corporate-proxy/

你可能想要检查你的NPM代理设置并删除它。

npm config get proxy
npm config rm proxy
npm config rm https-proxy

人们可能会期望一个新的NodeJS+NPM安装不会配置代理。奇怪的是,我的服务器确实定义了一个代理,指向一个IP和端口3128。删除代理起到了作用。

我们公司的防火墙将停止安装节点,因此连接到个人网络并安装,这对我来说是有效的。

这可能是由于使用sudo在npm中安装任何东西引起的——这会导致缓存中的文件由root拥有,从而导致这个问题。你可以通过运行:

Sudo rm -rf ~/.npm

删除缓存。然后再试一遍你正在做的任何事情,确保你从来没有在使用npm时同时使用sudo(否则问题可能会再次出现)。

更多信息:npm抛出错误没有sudo

在家里删除你的代理设置,在办公室网络上打开,这可能会让人恼火,但对我来说很管用:

npm config set proxy http://xxx.xxx.xxx.4:8080   
npm config set https-proxy http://xxx.xxx.xxx.4:8080

and

npm config rm proxy   
npm config rm https-proxy