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

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


当前回答

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

Sudo rm -rf ~/.npm

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

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

其他回答

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

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

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

yarn install

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

它为我解决了使用这段代码: NPM安装-g纱线

Yarn全局添加create-react-app

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

Sudo rm -rf ~/.npm

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

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

我发现“npm config edit”对更新http -proxy, proxy, registry的条目更有用

我是这样做的

NPM配置列表 NPM配置编辑(在vi中打开) 编辑或设置http -proxy、代理、注册表的配置项 npm安装

NPM配置设置http -proxy“http://username:password@proxy-url:proxy-port”对我有用