阅读.npmrc文件中的代理变量,但它不起作用。尽量避免手动下载所有需要的包并安装。
当前回答
尝试在C:\Users\.npmrc中找到。npmrc
然后打开(记事本),写入并保存在里面:
proxy=http://<username>:<pass>@<proxyhost>:<port>
PS:请删除“<”和“>”!!
其他回答
设置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
注意:http -proxy没有使用https作为协议,而是使用http。
如果有疑问,试试所有这些命令,就像我做的那样:
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
我尝试了所有这些选择,但出于某种原因,我的代理人没有任何选择。然后,出于绝望,我在Git Bash shell中随机尝试了curl,它起作用了。
清除使用的所有代理选项
npm config rm proxy
npm config rm https-proxy
然后在我的Git Bash shell中运行npm install,效果非常好。我不知道如何正确设置代理和Windows cmd提示符,但它工作。
这对我很管用
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
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/
推荐文章
- ReferenceError: description没有定义NodeJs
- 将一个二进制的NodeJS Buffer转换为JavaScript的ArrayBuffer
- AngularJS只适用于单页应用程序吗?
- 如何在vue-cli项目中更改端口号
- 如何查看npm包的大小?
- 同步和异步编程(在node.js中)的区别是什么?
- 如何编辑通过npm安装的节点模块?
- “node_modules”文件夹应该包含在git存储库中吗
- 使用package.json在全局和本地安装依赖项
- this.libOptions.parse不是一个函数
- 对嵌套文件夹运行npm install的最好方法是什么?
- 节点Multer异常字段
- 在Ubuntu上安装Bower
- 很好的初学者教程socket.io?
- CALL_AND_RETRY_LAST分配失败-进程内存不足