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


当前回答

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

其他回答

对我来说,尽管python等都可以工作,但我们的公司代理npm不会。

我试着

NPM配置设置代理http://proxyccc.xxx.ca:8080 NPM配置http -proxy https://proxyccc.xxx.ca:8080 NPM配置设置注册表http://registry.npmjs.org/

按照指示,但总是得到相同的错误。

只是当我移开的时候 https-proxy https://proxyccc.xxx.ca: 8080 从.npmrc文件 那 NPM安装电子——save-dev工作正常

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

如果有疑问,试试所有这些命令,就像我做的那样:

npm config set registry http://registry.npmjs.org/
npm config set proxy http://myusername:mypassword@proxy.us.somecompany:8080
npm config set https-proxy http://myusername:mypassword@proxy.us.somecompany:8080
npm config set strict-ssl false
set HTTPS_PROXY=http://myusername:mypassword@proxy.us.somecompany:8080
set HTTP_PROXY=http://myusername:mypassword@proxy.us.somecompany:8080
export HTTPS_PROXY=http://myusername:mypassword@proxy.us.somecompany:8080
export HTTP_PROXY=http://myusername:mypassword@proxy.us.somecompany:8080
export http_proxy=http://myusername:mypassword@proxy.us.somecompany:8080

npm --proxy http://myusername:mypassword@proxy.us.somecompany:8080 \
--without-ssl --insecure -g install

= = = = = = =

更新

将您的设置放入~/。Bashrc或~/。Bash_profile,这样你就不必担心你的设置每次打开一个新的终端窗口!

如果你的公司像我的公司一样,我必须经常更改密码。因此,我在~/中添加了以下内容。Bashrc或~/。这样每当我打开一个终端,我就知道我的npm是最新的!

Simply paste the following code at the bottom of your ~/.bashrc file: ###################### # User Variables (Edit These!) ###################### username="myusername" password="mypassword" proxy="mycompany:8080" ###################### # Environement Variables # (npm does use these variables, and they are vital to lots of applications) ###################### export HTTPS_PROXY="http://$username:$password@$proxy" export HTTP_PROXY="http://$username:$password@$proxy" export http_proxy="http://$username:$password@$proxy" export https_proxy="http://$username:$password@$proxy" export all_proxy="http://$username:$password@$proxy" export ftp_proxy="http://$username:$password@$proxy" export dns_proxy="http://$username:$password@$proxy" export rsync_proxy="http://$username:$password@$proxy" export no_proxy="127.0.0.10/8, localhost, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16" ###################### # npm Settings ###################### npm config set registry http://registry.npmjs.org/ npm config set proxy "http://$username:$password@$proxy" npm config set https-proxy "http://$username:$password@$proxy" npm config set strict-ssl false echo "registry=http://registry.npmjs.org/" > ~/.npmrc echo "proxy=http://$username:$password@$proxy" >> ~/.npmrc echo "strict-ssl=false" >> ~/.npmrc echo "http-proxy=http://$username:$password@$proxy" >> ~/.npmrc echo "http_proxy=http://$username:$password@$proxy" >> ~/.npmrc echo "https_proxy=http://$username:$password@$proxy" >> ~/.npmrc echo "https-proxy=http://$username:$password@$proxy" >> ~/.npmrc ###################### # WGET SETTINGS # (Bonus Settings! Not required for npm to work, but needed for lots of other programs) ###################### echo "https_proxy = http://$username:$password@$proxy/" > ~/.wgetrc echo "http_proxy = http://$username:$password@$proxy/" >> ~/.wgetrc echo "ftp_proxy = http://$username:$password@$proxy/" >> ~/.wgetrc echo "use_proxy = on" >> ~/.wgetrc ###################### # CURL SETTINGS # (Bonus Settings! Not required for npm to work, but needed for lots of other programs) ###################### echo "proxy=http://$username:$password@$proxy" > ~/.curlrc Then edit the "username", "password", and "proxy" fields in the code you pasted. Open a new terminal Check your settings by running npm config list and cat ~/.npmrc Try to install your module using npm install __, or npm --without-ssl --insecure install __, or override your proxy settings by using npm --without-ssl --insecure --proxy http://username:password@proxy:8080 install __. If you want the module to be available globally, add option -g

我是这样解决这个问题的:

我运行这个命令: NPM配置strict-ssl为false 然后设置npm运行http,而不是https: NPM配置注册表http://registry.npmjs.org/ 然后我使用下面的语法安装包: NPM——proxy http://username:password@cacheaddress.com.br:80安装packagename

如果代理不要求您进行身份验证,则跳过用户名:密码部分

编辑:我的一个朋友刚刚指出,你可以通过设置HTTP_PROXY和HTTPS_PROXY环境变量来让NPM在代理后工作,然后正常地发出命令NPM install express(例如)

EDIT2:正如@ bstruthers评论的那样,请记住,包含“@”的密码不会被正确解析,如果包含@,则将整个密码放在引号中

虽然我在配置中设置了代理,但问题并没有解决 这个对我很有用:

npm——http -proxy http://XX.AA.AA.BB:8080安装cordova插件 npm——代理http://XX.AA.AA.BB:8080安装