使用ng new创建Angular项目遇npm网络错误,求解决方案
解决方案
1. 检查并处理代理配置
- 查看当前npm代理设置:
npm config get proxy npm config get https-proxy - 若处于代理环境,配置正确的代理地址:
npm config set proxy http://代理地址:端口 npm config set https-proxy http://代理地址:端口 - 若无需代理,清空现有代理配置:
npm config delete proxy npm config delete https-proxy
2. 切换npm镜像源
默认官方源访问不稳定时,切换为国内镜像:
npm config set registry https://registry.npmmirror.com/
验证镜像源切换结果:
npm config get registry
3. 清理npm缓存
缓存损坏可能引发网络请求异常,执行强制清理:
npm cache clean --force
4. 手动分步创建项目
跳过CLI自动安装流程,手动完成依赖安装:
- 生成项目骨架(不自动安装依赖):
ng new ang-routing --skip-install - 进入项目目录:
cd ang-routing - 手动安装所有依赖:
npm install
5. 排查网络连接问题
- 测试npm registry的连通性:
ping registry.npmjs.org - 若无法连通,检查本地网络状态,尝试切换网络环境(如更换WiFi或使用手机热点)。
内容的提问来源于stack exchange,提问作者ezhil .n
相关产品推荐
相关产品推荐

