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

Angular项目编译失败求助:NGCC初始化失败等相关报错

Angular编译失败(NGCC执行失败)解决方案

报错信息

./src/main.ts - 错误:模块构建失败(来自./node_modules/@ngtools/webpack/src/ivy/index.js):
错误:Angular Webpack插件初始化前尝试进行输出操作。
错误:Angular编译初始化失败 - NGCC执行失败。

解决步骤

  • 清理依赖与缓存

    1. 删除本地依赖文件夹和锁文件:
      # macOS/Linux
      rm -rf node_modules package-lock.json
      # Windows
      rmdir /s /q node_modules && del package-lock.json
      
    2. 重新安装依赖:npm install
    3. 手动触发NGCC编译:npx ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points
  • 统一Angular核心包版本
    执行ng version查看@angular/cli、@angular/core、@angular/compiler等包的版本,确保所有核心包版本完全一致,若存在版本差异,修改package.json后重新执行npm install

  • 临时禁用Ivy编译(可选)
    打开angular.json,找到项目构建配置projects -> [项目名称] -> architect -> build -> options,添加配置项:

    "enableIvy": false
    

    保存后重新执行ng serve

  • 清理Angular CLI缓存
    执行ng cache clean清除CLI缓存后再尝试启动项目

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 06:15:00