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

升级至Angular V15.1.2后无法通过Angular CLI生成组件

Angular 15.1.2升级后ng g c等CLI生成命令报错:Cannot destructure property 'aliases'...

问题背景

项目升级至Angular 15.1.2后,执行ng g c components/test这类基础CLI生成命令时触发报错,同环境下运行Angular 15.0.1的项目无此问题,已排除Node/NPM版本异常,团队成员均遇到相同情况,推测为升级后的项目配置异常导致。

报错信息

发生未处理的异常:无法解构'collection.description.schematics[schematicName]'的属性'aliases',因为它未定义。
查看"C:\Users\david\AppData\Local\Temp\ng-4fyV7s\angular-errors.log"获取详细信息。

详细栈追踪

[error] TypeError: Cannot destructure property 'aliases' of 'collection.description.schematics[schematicName]' as it is undefined.
at GenerateCommandModule.getSchematics (C:\Projects\GitHub\app\node_modules@angular\cli\src\commands\generate\cli.js:141:29)
at getSchematics.next ()
at GenerateCommandModule.getSchematicsToRegister (C:\Projects\GitHub\pau-pe-shutdownreporting\shutdown-app\node_modules@angular\cli\src\commands\generate\cli.js:158:76)
at async GenerateCommandModule.builder (C:\Projects\GitHub\app\node_modules@angular\cli\src\commands\generate\cli.js:35:55)
at async runCommand (C:\Projects\GitHub\app\node_modules@angular\cli\src\command-builder\command-runner.js:113:5)
at async default_1 (C:\Projects\GitHub\app\node_modules@angular\cli\lib\cli\index.js:70:16)

解决步骤

1. 检查并修复angular.json的schematics配置

报错核心原因是项目配置中缺少或错误引用了schematics集合:

  • 打开项目根目录的angular.json,找到项目配置下的schematics节点(与architect同级)
  • 确保配置包含Angular官方schematics,示例:
"schematics": {
  "@schematics/angular": {}
}

若有自定义schematics配置,检查是否存在拼写错误或引用了不存在的集合。

2. 清理依赖并重新安装

执行以下命令清理旧依赖后重装:

rm -rf node_modules package-lock.json
npm install

(Windows PowerShell环境可替换为:Remove-Item -Recurse -Force node_modules, package-lock.json; npm install)

3. 对齐Angular CLI版本

确保全局与本地CLI版本均匹配项目的Angular 15.1.2:

  • 查看当前版本:ng version
  • 更新全局CLI:npm install -g @angular/cli@15.1.2
  • 更新本地CLI:npm install @angular/cli@15.1.2 --save-dev

4. 排查第三方schematics冲突

若项目使用了第三方schematics库(如自定义生成器),临时移除相关配置后测试命令是否正常。若恢复正常,说明该库不兼容Angular 15.1.2,需等待库更新或替换方案。

5. 重置CLI配置

以上步骤无效时,尝试重置CLI配置并重新初始化官方schematics:

ng config clear
ng add @schematics/angular

内容的提问来源于stack exchange,提问作者dmoore1181

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 14:20:40