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


当前回答

要设置http代理,请设置-g标志:

Sudo NPM配置代理http://proxy_host:port -g

对于https代理,再次确保设置了-g标志:

Sudo NPM配置http -proxy http://proxy_host:port -g

其他回答

最后,我已经设法解决了这个问题背后的代理与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/
npm config set proxy <http://...>:<port_number>
npm config set registry http://registry.npmjs.org/

这解决了我的问题。

你尝试过命令行选项而不是.npmrc文件吗?

我认为类似于npm——proxy http://proxy-server:8080/ install {package-name}的东西对我有用。

我还看到了以下内容: NPM配置设置代理http://proxy-server:8080/

这对我很管用

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

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

清除使用的所有代理选项

npm config rm proxy
npm config rm https-proxy

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