You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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自动安装流程,手动完成依赖安装:

  1. 生成项目骨架(不自动安装依赖):
    ng new ang-routing --skip-install
    
  2. 进入项目目录:
    cd ang-routing
    
  3. 手动安装所有依赖:
    npm install
    

5. 排查网络连接问题

  • 测试npm registry的连通性:
    ping registry.npmjs.org
    
  • 若无法连通,检查本地网络状态,尝试切换网络环境(如更换WiFi或使用手机热点)。

内容的提问来源于stack exchange,提问作者ezhil .n

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 14:12:34