npm install
在代理后面工作?我尝试在.npmrc
文件中更改代理变量,但没有成功。我想避免手动下载。I run this command:
npm config set strict-ssl false
Then set npm to run with http, instead of https:
npm config set registry "http://registry.npmjs.org/"
Then I install packages using this syntax:
npm --proxy http://username:password@cacheaddress.com.br:80 install packagename
username:password
部分。设置 npm
代理
对于 HTTP
:
npm config set proxy http://proxy_host:port
对于 HTTPS
:
如果存在 https 代理地址,则使用该地址。
npm config set https-proxy https://proxy.company.com:8080
否则重复使用http代理地址
npm config set https-proxy http://proxy.company.com:8080
注意: https 代理的协议不是 https
,而是 http
。
npm config set registry "http://registry.npmjs.org/"
。它奏效了 :) - Travis Le当有疑问时,尝试所有这些命令,就像我一样:
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
或~/.bash_profile
文件中,这样每次打开终端时,您的npm就是最新版本!
只需将以下代码粘贴到~/.bashrc
文件的底部即可:
######################
# 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
然后编辑你所复制的代码中的 "用户名"、"密码" 和 "代理" 字段。
打开一个新终端。
通过运行 npm config list
和 cat ~/.npmrc
检查你的设置。
尝试使用以下命令安装模块:
npm install __
,或者npm --without-ssl --insecure install __
,或者npm --without-ssl --insecure --proxy http://username:password@proxy:8080 install __
覆盖你的代理设置。-g
。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
来配置 npm,然后使用 npm --proxy http://myusername:mypassword@proxy.us.somecompany:8080 --without-ssl --insecure -g install {packagename}
安装了 npm 包。谢谢。 - Atur您是否尝试过使用命令行选项而不是 .npmrc
文件?
我认为像这样的命令可以解决问题:npm --proxy http://proxy-server:8080/ install {package-name}
。
我也看到了下面的命令:npm config set proxy http://proxy-server:8080/
虽然已经有很多好的建议,但对于我的环境(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
这在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
。encodeURIComponent("YourP@ssword")
来获取密码的编码版本。 - jaggedsoft设置http代理,请设置-g标志:
sudo npm config set proxy http://proxy_host:port -g
对于https代理,请再次确保-g标志已设置:
sudo npm config set https-proxy http://proxy_host:port -g
npm config set proxy http://domain%5Cuser:password@proxy:port/
npm config set https-proxy http://domain%5Cuser:password@proxy:port/
在URL中编码任何特殊字符,如反斜杠或#号,非常重要。
backshlash
需要用%5C进行编码,因此domain\user
将变为domain%5Cuser
%23%0A
对#
符号进行编码,因此像Password#2
这样的密码将变为Password%23%0A2
我还添加了以下设置:
npm config set strict-ssl false
npm config set registry http://registry.npmjs.org/
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
npm set strict-ssl=false
$ npm config set proxy http://login:pass@host:port
$ npm config set https-proxy http://login:pass@host:port
my@password
,则您的.npmrc
文件中密码部分应为my%40password
。用引号括起来在某些情况下可行,但编码更为可靠。 - Chris Jaynes