安装Angular CLI时出现400 Bad Request错误,寻求解决方案
解决npm安装Angular CLI时出现400 Bad Request错误的方案
我之前也碰到过类似的代理配置导致的npm请求错误,结合你的情况,大概率是代理设置有误引发的问题,给你几个可行的解决步骤:
1. 修正错误的代理配置
你的命令里有两个关键问题:
proxy-http不是npm官方支持的配置项,正确的HTTPS代理配置应该用https-proxy- 代理地址缺少协议前缀(
http://或https://),npm无法正确识别代理服务器的访问路径
先清理错误的配置:
npm config delete proxy npm config delete proxy-http
然后重新设置正确的代理(根据你的代理类型调整协议):
# 如果是HTTP代理 npm config set proxy http://myproxy.com:1234 npm config set https-proxy http://myproxy.com:1234 # 如果代理需要用户名密码认证,格式如下 # npm config set proxy http://username:password@myproxy.com:1234 # npm config set https-proxy http://username:password@myproxy.com:1234
2. 确保npm registry配置正确
代理配置冲突可能导致registry访问异常,你可以重置为官方默认registry:
npm config set registry https://registry.npmjs.org/
3. 清理npm缓存
缓存损坏也可能引发请求错误,执行以下命令清理缓存:
# npm 6及以下版本 npm cache clean --force # npm 7+版本(推荐) npm cache verify
4. 重试安装适配Angular 4的CLI版本
完成以上配置后,重新执行安装命令——注意Angular 4对应的CLI是1.x系列,建议指定稳定版本:
npm install -g @angular/cli@1.7.4
如果以上步骤都无效,你可以尝试跳过代理,直接用国内镜像源安装:
npm install -g @angular/cli@1.7.4 --registry=https://registry.npmmirror.com
内容的提问来源于stack exchange,提问作者aj go
相关产品推荐
相关产品推荐

