node.js 代理配置后无法 npm install Angular-cli
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47029317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to npm install Angular-cli after proxy configuration
提问by icedmilocode
I am trying to download Angular in Windows 10 using npm install. As I am on corporate proxy, I configured the proxy to username:password@server:port
我正在尝试使用 npm install 在 Windows 10 中下载 Angular。当我使用公司代理时,我将代理配置为 username:password@server:port
However, I am facing this issue when running
但是,我在运行时遇到了这个问题
npm ERR! code E407
npm ERR! 407 Proxy Authorization Required: @angular/cli@latest
npm ERR! code E407
npm ERR! 407 Proxy Authorization Required: @angular/cli@latest
The debug log as followed:
调试日志如下:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli '--proxy',
1 verbose cli 'http://XXXXX', //Removed my proxy details
1 verbose cli '--without-ssl',
1 verbose cli '--insecure',
1 verbose cli '-g',
1 verbose cli 'install',
1 verbose cli '@angular/cli' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 40ab1dc3dabb6029
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 407 http://registry.npmjs.org/@angular%2fcli 109ms
8 silly fetchPackageMetaData error for @angular/cli@latest 407 Proxy Authorization Required: @angular/cli@latest
9 verbose stack Error: 407 Proxy Authorization Required: @angular/cli@latest
9 verbose stack at fetch.then.res (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\fetch.js:42:19)
9 verbose stack at tryCatcher (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
9 verbose stack at Promise._settlePromiseFromHandler (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:512:31)
9 verbose stack at Promise._settlePromise (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:569:18)
9 verbose stack at Promise._settlePromise0 (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:614:10)
9 verbose stack at Promise._settlePromises (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:693:18)
9 verbose stack at Async._drainQueue (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:133:16)
9 verbose stack at Async._drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:143:10)
9 verbose stack at Immediate.Async.drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:17:14)
9 verbose stack at runCallback (timers.js:785:20)
9 verbose stack at tryOnImmediate (timers.js:747:5)
9 verbose stack at processImmediate [as _immediateCallback] (timers.js:718:5)
10 verbose cwd C:\Users\XXXXX
11 verbose Windows_NT 10.0.14393
12 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "--proxy" "http://XXXXX" "--without-ssl" "--insecure" "-g" "install" "@angular/cli"
13 verbose node v8.8.1
14 verbose npm v5.4.2
15 error code E407
16 error 407 Proxy Authorization Required: @angular/cli@latest
17 verbose exit [ 1, true ]
Any idea what could have cause the issue? Thanks!
知道是什么导致了这个问题吗?谢谢!
回答by Ala Messaoudi
This configuration worked for me :
这个配置对我有用:
method1 (command line):
方法1(命令行):
npm config set proxy http://user:password@domain_proxy:port/
npm config set https-proxy http://user:password@domain_proxy:port
be careful the url should be encoded. for example this password 01xx!tr should be introduced as 01xx%21tr. use this site to encode your url https://www.url-encode-decode.com/
example:
user/password => user1/01xx!tr
domain:port of the proxy => mydomain.org:8000
=> in that case :
npm config set proxy http://user1:01xx%[email protected]:8000/
npm config set https-proxy http://user1:01xx%[email protected]:8000
method2 (edit node conifugration file):
方法2(编辑节点配置文件):
the method 2 is easier because we will not be botherd with encoding the urls
1- edit node configuration file (in windows it's located in %USERPROFILE%\.npmrc, example C:\Users\Hyman\.npmrc)
2- add these lines
proxy=http://user:password@domain_proxy:port/
https-proxy=https-proxy http://user:passwor`enter code here`d@domain_proxy:port
example :
if the :
user/password => user1/01xx!tr
domain:port of the proxy => mydomain.org:8000
=> the configuration file should be look like this:
proxy=http://user1:[email protected]:8000/
https-proxy=http://user1:[email protected]:8000
回答by Naveen Kumar G C
回答by Yanish Pradhananga
If you have configured Proxy and Still you are not able to install using npm command. You can try below command. It seemed you need to clear some stuff - and that will fix the issue.
如果您已经配置了 Proxy 并且您仍然无法使用 npm 命令进行安装。你可以试试下面的命令。似乎您需要清除一些东西 - 这将解决问题。
npm cache verify
回答by Yash
This steps worked for me
这些步骤对我有用
Edit .npmrcfile
add below lines
编辑.npmrc文件添加以下行
proxy=http://username:password@proxyaddress:portno
https-proxy=http://username:password@proxyaddress:portno
回答by Dking
The thing that worked for me as below, Issue: Registry defined at "C:\Users*user-name*.npmrc" was wrong. Need to update npm config registry.
对我有用的事情如下,问题:在“C:\Users*user-name*.npmrc”中定义的注册表是错误的。需要更新 npm 配置注册表。
Step 1 Solution: Removed registry entry from "C:\Users*user-name*.npmrc" file.
步骤 1 解决方案:从“C:\Users*user-name*.npmrc”文件中删除注册表项。
Step 2 After Step 1 I got below error
第 2 步在第 1 步之后我得到以下错误
npm install -g @angular/cli npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning SELF_SIGNED_CERT_IN_CHAIN: request to https://registry.npmjs.org/@angular%2fclifailed, reason: self signed certificate in certificate chain npm WARN registry Using stale package data from https://registry.npmjs.org/due to a request error during revalidation.
npm install -g @angular/cli npm WARN registry https://registry.npmjs.org/ 的意外警告:杂项警告 SELF_SIGNED_CERT_IN_CHAIN:对https://registry.npmjs.org/@angular%2fcli 的请求失败,原因:self证书链 npm WARN 注册表中的签名证书由于重新验证期间的请求错误,使用来自https://registry.npmjs.org/ 的陈旧包数据。
Issue: The npm maintainers announced on February 27th that npm's Self-Signed Certificate is No More: A bunch of users received a “SELFSIGNEDCERTINCHAIN” error during installing and publishing packages throughout the day today. npm no longer supports its self-signed certificates. However, the recommended fix failed for me.
问题:npm 维护者于 2 月 27 日宣布,npm 的自签名证书已不复存在:今天,一群用户在安装和发布软件包时收到了“SELFSIGNEDCERTINCHAIN”错误。npm 不再支持其自签名证书。但是,推荐的修复对我来说失败了。
Solution: Open command prompt, and run below commands. SETLOCAL SET npm_config_strict-ssl=false npm install npm -g --ca=null npm --version ENDLOCAL
解决方案:打开命令提示符,然后运行以下命令。SETLOCAL SET npm_config_strict-ssl=false npm install npm -g --ca=null npm --version ENDLOCAL
Step 3 Now >npm install -g @angular/cli running all ok.
第 3 步现在 >npm install -g @angular/cli 运行一切正常。
回答by New_Coder
To config proxy in office,
要在办公室配置代理,
npm config set proxy http://user:[email protected]:port/
npm config set https-proxy http://user:[email protected]:port/
回答by Spyder
Solved it. After I spent a bit of time on proxy issues, it turns out my mistake was setting 3 proxy variables: proxy, http-proxyand https-proxy.
解决了。在我花了一些时间处理代理问题后,我发现我的错误是设置了 3 个代理变量:proxy、http-proxy和https-proxy。
(note: I read somewhere on stackoverflow that I was supposed to set http-proxybut this is wrong)
(注意:我在stackoverflow上的某个地方读到我应该设置http-proxy,但这是错误的)
Removing http-proxysolved this for me.
删除http-proxy为我解决了这个问题。
Setting npm proxy and npm https_proxy is correct, as follows:
设置npm proxy和npm https_proxy是正确的,如下:
npm config set proxy http://user:[email protected]:port/
npm config set https-proxy http://user:[email protected]:port/

