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


当前回答

这对我很管用

npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
npm set strict-ssl=false

其他回答

对于这个问题,上面有很多答案,但没有一个对我有用。他们都提到要添加http://前缀。所以我也加了进去。都失败了。

它终于工作后,我不小心删除了http://前缀。最终配置如下:

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

我不知道这背后的逻辑,但它奏效了。如果以上答案都不适合你,也许你可以试试这种方法。希望这个对你有用。

最后,我已经设法解决了这个问题背后的代理与AD认证。我必须执行:

npm config set proxy http://domain%5Cuser:password@proxy:port/
npm config set https-proxy http://domain%5Cuser:password@proxy:port/

URL编码任何特殊字符(如反斜杠或#)是非常重要的 在我的情况下,我必须编码

反shashly %5C,这样域\user将是域%5Cuser #使用%23%0A,这样密码#2将是密码%23%0A2

我还添加了以下设置:

npm config set strict-ssl false
npm config set registry http://registry.npmjs.org/

虽然已经有很多好的建议,但对于我的环境(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

希望这能节省别人的时间

很多应用程序(例如npm)可以使用用户环境变量的代理设置。

您可以向您的环境中添加以下变量HTTP_PROXY和HTTPS_PROXY,它们对于每个变量都具有相同的值

http://user:password@proxyAddress:proxyPort

例如,如果你有Windows,你可以添加代理如下:

在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为端口。根据您的代理设置进行更改。这对我很有用。