阅读.npmrc文件中的代理变量,但它不起作用。尽量避免手动下载所有需要的包并安装。
当前回答
很多应用程序(例如npm)可以使用用户环境变量的代理设置。
您可以向您的环境中添加以下变量HTTP_PROXY和HTTPS_PROXY,它们对于每个变量都具有相同的值
http://user:password@proxyAddress:proxyPort
例如,如果你有Windows,你可以添加代理如下:
其他回答
Windows系统
尝试删除代理和注册表设置(如果已经设置),并通过命令行设置环境变量
SET HTTP_PROXY=http://username:password@domain:port
SET HTTPS_PROXY=http://username:password@domain:port
然后尝试运行NPM install。这样,你就不用在.npmrc中设置代理了,但是对于那个会话,它是可以工作的。
vim ~ /。npmrc,并添加以下内容。不要忘记添加注册表部分,因为这在很多情况下会导致失败。
proxy=http://<proxy-url>:<port>
https-proxy=https://<proxy-url>:<port>
registry=http://registry.npmjs.org/
对于这个问题,上面有很多答案,但没有一个对我有用。他们都提到要添加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
我不知道这背后的逻辑,但它奏效了。如果以上答案都不适合你,也许你可以试试这种方法。希望这个对你有用。
这对我来说在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用于字符\。
如果有疑问,试试所有这些命令,就像我做的那样:
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 start和npm run start的区别
- 有没有办法修复包锁。json lockfileVersion所以npm使用特定的格式?
- 如何使用npm全局安装一个模块?
- 实时http流到HTML5视频客户端的最佳方法
- 使用node.js下载图像
- Node.js Express中的HTTP GET请求
- Node.js:将文本文件读入数组。(每一行都是数组中的一项。)
- npm犯错!错误:EPERM:操作不允许,重命名
- Node Sass还不支持当前环境:Linux 64位,带false
- 我如何添加环境变量启动。VSCode中的json
- 解析错误:无法读取文件“…/tsconfig.json”.eslint
- 编译typescript时'tsc命令未找到'
- 在Node.js中'use strict'语句是如何解释的?
- 当WebSockets可用时,为什么要使用AJAX ?
- 使用过程。TypeScript中的env