gpt4 book ai didi

node.js - 代理配置后无法 npm 安装 Angular-cli

转载 作者:太空宇宙 更新时间:2023-11-03 22:41:34 26 4
gpt4 key购买 nike

我正在尝试使用 npm install 在 Windows 10 中下载 Angular。由于我使用的是公司代理,因此我将代理配置为 username:password@server:port

但是,我在运行时遇到了这个问题

npm 错误!代码 E407
npm 错误! 407 需要代理授权:@angular/cli@latest

调试日志如下:

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 npm@5.4.2
3 info using node@v8.8.1
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 ]

知道是什么原因导致了这个问题吗?谢谢!

最佳答案

这个配置对我有用:

方法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%21tr@mydomain.org:8000/
npm config set https-proxy http://user1:01xx%21tr@mydomain.org:8000

方法2(编辑 Node 配置文件):

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\Jack\.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:01xx!tr@mydomain.org:8000/
https-proxy=http://user1:01xx!tr@mydomain.org:8000

关于node.js - 代理配置后无法 npm 安装 Angular-cli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47029317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com