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


当前回答

最后,我已经设法解决了这个问题背后的代理与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/

其他回答

尝试在C:\Users\.npmrc中找到。npmrc

然后打开(记事本),写入并保存在里面:

proxy=http://<username>:<pass>@<proxyhost>:<port>

PS:请删除“<”和“>”!!

当我在代理设置中没有http/http前缀时,即使代理主机和端口是正确的值,npm也会失败。只有在添加协议前缀后,它才能正常工作。

对于这个问题,上面有很多答案,但没有一个对我有用。他们都提到要添加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中是有效的:

npm config set proxy http://domain%5Cuser:pass@host:port

如果您不在任何域中,请使用:

npm config set proxy http://user:pass@host:port

如果您的密码包含特殊字符,如“,@,:等,请将它们替换为URL编码值。例如“->%22,@->%40,:->%3A。%5C用于字符\。