node.js - 在代理服务器后面的 Windows 10 上安装 Angular CLI 时出现 400 错误
问题描述
我刚开始学习 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 错误请求 - 获取 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 ]
您能否让我知道我在这里缺少什么以及如何解决该问题。
谢谢你的帮助。
更新(解决方案)
感谢您的意见。我检查了 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/
解决方案
我使用 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/
推荐阅读
- swift - 如何使 SKSpriteNode 避免另一个 SKSpriteNode?
- python - 使用 matplotlib 绘制两个时间序列数据帧和一个数据帧中的一些缺失日期
- html - bootstrap 4 网格类 col-4 中的最大图片宽度和高度是多少。帮助减少模糊图像的命令
- javascript - 无法运行“npm start”
- c# - 如何在 README 文件中将链接显示为纯文本
- azure - 如何将测试计划许可证用户添加到 Azure DevOps 服务组织?
- excel - EXCEL 使用 INDEX 和 MAX 计算最大值时查找单元格文本
- r - 无法在循环中显示 abline
- reactjs - 使用 React、Axios 和 MovieDB 将 x 数量的 API 电影返回到无序列表中
- c# - 在多个类中使用相同的变量