我有一个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

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


当前回答

我在没有代理的本地家庭网络上遇到了同样的问题。这个帖子里的其他答案对我不起作用。我最后做的是使用yarn,它可以和npm互换使用:

yarn add

直到今天,我不知道为什么我的npm仍然不能工作。我知道这肯定是我的Wi-Fi有问题,因为当我连接到LTE网络时,npm安装又开始工作了。这可能与路由器设置有关(当我升级网速时,ISP工作人员将我的旧路由器更换为新的时,问题就出现了)。

其他回答

如果保存的不记名令牌现在无效,也可能遇到此错误。我在使用私人回购时遇到过这种情况,其中帐户被擦除和重置,令牌无效。虽然你的回购可能不需要身份验证,如果你有一个令牌从以前的登录,它将被通过,如果它是无效的连接将被关闭。

您可以通过使用新的用户名和密码再次登录来解决这个问题,或者简单地通过npm注销。

这是个老问题了。

当我试图部署到heroku时,我遇到了这个问题,对我有效的修复是更新所使用的npm版本。我有版本2.x。我更新到3.x.x

工作时,我必须打开浏览器浏览一个网页(这可以让我通过我们的网络过滤器)。然后我重新尝试了命令,它成功地工作了。

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

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

我也遇到了同样的问题,但这些解决方案都不能正确工作。最后,我通过yarn安装了包,这是npm兼容的。根据官方网站:

对大多数用户来说,从npm迁移应该是一个相当简单的过程。 纱线可以消耗相同的包装。Json格式为npm,并可以安装 来自NPM注册表的任何包。

只需要安装yarn,然后使用下面的命令运行install,相当于npm install in yarn:

yarn install

阅读更多- Yarn:从npm迁移。