在代理服务器后面的Windows 10上安装Angular CLI时出现400错误

时间:2019-12-18 14:36:47

标签: node.js angular angular-cli

我刚刚开始学习angular,需要在代理服务器后面的PC(Windows 10)上安装Angular CLI。我的节点版本为 v12.13.1 ,npm版本为 6.12.1

我转到设置->网络和Internet->代理,将整个值复制到“脚本地址”字段中,并使用该值更新配置文件:

https-proxy=Script address value
proxy=Script address value

现在,当我运行npm install -g @angular/cli时,出现以下错误消息:

  

npm错误! 400错误的请求-GET   https://registry.npmjs.org/@angular%2fcli

这是日志文件:

0 info it worked if it ends with ok
1 verbose cli [
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   'install',
1 verbose cli   '-g',
1 verbose cli   '@angular/cli'
1 verbose cli ]
2 info using npm@6.12.1
3 info using node@v12.13.1
4 verbose npm-session 273f364019e6cde2
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 400 https://registry.npmjs.org/@angular%2fcli 643ms
8 silly fetchPackageMetaData error for @angular/cli@latest 400 Bad Request - GET https://registry.npmjs.org/@angular%2fcli
9 timing stage:rollbackFailedOptional Completed in 1ms
10 timing stage:runTopLevelLifecycles Completed in 968ms
11 verbose stack Error: 400 Bad Request - GET https://registry.npmjs.org/@angular%2fcli
11 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-fetch\check-response.js:104:15
11 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:93:5)
12 verbose statusCode 400
13 verbose pkgid @angular/cli@latest
14 verbose cwd C:\Program Files\nodejs
15 verbose Windows_NT 10.0.18362
16 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "@angular/cli"
17 verbose node v12.13.1
18 verbose npm  v6.12.1
19 error code E400
20 error 400 Bad Request - GET https://registry.npmjs.org/@angular%2fcli
21 verbose exit [ 1, true ]

请让我知道我在这里想念什么以及如何解决该问题。

感谢您的帮助。

UPDATE(解决方案)

感谢您的评论。我检查了URL,并将代理更改为localhost,它可以工作。配置文件如下所示:

proxy=http://localhost:8888/proxy.pac
https-proxy=http://localhost:8888/proxy.pac
http-proxy=http://localhost:8888/proxy.pac
registry=http://registry.npmjs.org/

1 个答案:

答案 0 :(得分:0)

我使用localhost而不是我们的代理URL,它解决了该问题。下面是我的配置文件:

proxy=http://localhost:8888/proxy.pac
https-proxy=http://localhost:8888/proxy.pac
http-proxy=http://localhost:8888/proxy.pac
registry=http://registry.npmjs.org/