阅读.npmrc文件中的代理变量,但它不起作用。尽量避免手动下载所有需要的包并安装。


当前回答

虽然已经有很多好的建议,但对于我的环境(Windows 7,使用PowerShell)和最后一个可用的node.js版本(v8.1.2),上述所有建议都不起作用,除非我遵循brunowego设置。

检查你的设置:

npm config list

代理背后的设置:

npm config set registry http://registry.npmjs.org/
npm config set http-proxy http://username:password@ip:port
npm config set https-proxy http://username:password@ip:port
npm config set proxy http://username:password@ip:port
npm set strict-ssl false

希望这能节省别人的时间

其他回答

在cmd或GIT Bash或其他提示符下使用以下命令

$ NPM配置代理http://192.168.1.101:4128

$ NPM配置http -proxy http://192.168.1.101:4128

其中192.168.1.101为代理IP, 4128为端口。根据您的代理设置进行更改。这对我很有用。

去环境变量和删除或设置为空

HTTP_PROXY和HTTPS_PROXY

这也将解决企业环境的代理问题

$ npm config set proxy http://login:pass@host:port
$ npm config set https-proxy http://login:pass@host:port
npm config set proxy <http://...>:<port_number>
npm config set registry http://registry.npmjs.org/

这解决了我的问题。

我尝试了所有这些选择,但出于某种原因,我的代理人没有任何选择。然后,出于绝望,我在Git Bash shell中随机尝试了curl,它起作用了。

清除使用的所有代理选项

npm config rm proxy
npm config rm https-proxy

然后在我的Git Bash shell中运行npm install,效果非常好。我不知道如何正确设置代理和Windows cmd提示符,但它工作。