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

Angular升级至v6.0.0后ng build始终生成angular.io.example求助

解决Angular 6升级后ng build生成angular.io.example的问题

你遇到的这个情况,大概率是升级Angular到v6.0.0时,CLI配置文件出现了异常,尤其是新的angular.json(Angular 6开始替代旧版.angular-cli.json)的配置项出错导致的。下面给你几个排查和解决的方向:

1. 检查angular.json的defaultProject配置

Angular 6的CLI会通过顶层的defaultProject字段确定默认构建的项目,如果这个值被错误设置成了angular.io.example,或者指向了不存在的项目,就会触发这个问题:

  • 打开项目根目录的angular.json文件
  • 找到最外层的"defaultProject"字段,确认它的值是你实际的项目名称(比如你的项目叫my-demo,这里就应该写"my-demo")
  • 修改后保存,再重新执行ng build试试

2. 构建时显式指定项目名称

如果你的angular.json里有多个项目配置,或者defaultProject没配置对,可以在构建命令里明确指定项目:

ng build --project=你的项目名称

这样CLI就会精准定位到你要构建的项目,不会 fallback 到错误的示例项目。

3. 统一CLI相关依赖版本

从你给出的依赖信息来看,@angular-devkit/schematics是0.6.0,而其他devkit包是0.5.13,版本不匹配可能导致CLI行为异常。Angular 6对应的CLI版本应该是6.x.x,建议统一升级:

  • 先卸载当前CLI:
npm uninstall -g @angular/cli
npm uninstall @angular/cli
  • 重新安装Angular 6.0.0版本的CLI:
npm install -g @angular/cli@6.0.0
npm install @angular/cli@6.0.0 --save-dev
  • 再用ng update同步其他依赖:
ng update @angular/cli
ng update @angular/core

4. 清理缓存后重试

有时候缓存文件会引发奇怪的问题,你可以清理缓存和依赖后重新安装:

rm -rf node_modules
rm package-lock.json
npm cache clean --force
npm install

之后再尝试执行ng build命令。

如果以上方法都没解决,建议你把angular.json里的项目配置部分贴出来,这样能更精准地定位问题~

内容的提问来源于stack exchange,提问作者여대엽학부생

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 04:07:53