Angular ng serve 产生错误:NGCC 失败

Ser*_*hii 10 javascript typescript angular

运行后,ng serve我在终端窗口中出现异常:

编译@angular/core : 模块为 esm5

Error: Error on worker #1: TypeError: Cannot read property 'map' of undefined
Run Code Online (Sandbox Code Playgroud)

并在下面留言:

An unhandled exception occurred: NGCC failed.
Run Code Online (Sandbox Code Playgroud)

有关/tmp/ng-EAdxWj/angular-errors.log更多详细信息,请参阅。

角度errors.log:

[error] Error: NGCC failed.
    at NgccProcessor.process (/IdeaProjects/app/frontend/node_modules/@ngtools/webpack/src/ngcc_processor.js:76:19)
    at /IdeaProjects/app/frontend/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:579:31
    at SyncHook.eval [as call] (eval at create (/IdeaProjects/app/frontend/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
    at SyncHook.lazyCompileHook (/IdeaProjects/app/frontend/node_modules/tapable/lib/Hook.js:154:20)
    at Object.webpack [as webpackFactory] (/IdeaProjects/app/frontend/node_modules/webpack/lib/webpack.js:55:30)
    at createWebpack (/IdeaProjects/app/frontend/node_modules/@angular-devkit/build-webpack/src/webpack-dev-server/index.js:20:36)
    at Object.runWebpackDevServer (/IdeaProjects/app/frontend/node_modules/@angular-devkit/build-webpack/src/webpack-dev-server/index.js:46:12)
    at SwitchMapSubscriber.project (/IdeaProjects/app/frontend/node_modules/@angular-devkit/build-angular/src/dev-server/index.js:191:32)
    at SwitchMapSubscriber._next (/IdeaProjects/app/frontend/node_modules/@angular-devkit/build-angular/node_modules/rxjs/internal/operators/switchMap.js:49:27)
    at SwitchMapSubscriber.Subscriber.next (/IdeaProjects/app/frontend/node_modules/@angular-devkit/build-angular/node_modules/rxjs/internal/Subscriber.js:66:18)
    at /IdeaProjects/app/frontend/node_modules/@angular-devkit/build-angular/node_modules/rxjs/internal/util/subscribeToPromise.js:7:24
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Run Code Online (Sandbox Code Playgroud)

小智 22

刚刚有同样的问题。

通过向 tsconfig.app.json 添加以下内容来修复它:

"angularCompilerOptions": {
    "enableIvy": false
},
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助

  • 为什么这有效?该应用程序在同事的计算机上运行良好,但在我的计算机上运行不佳。这解决了这个问题,但这并不是真正的解决方案,因为这个修复并不理想。 (4认同)
  • @Felix,这意味着您禁用了 Ivy 编译器,因此使用旧的编译器(AOT)。您确定这是正确的解决方案吗? (4认同)
  • 我使用的是 Angular 11,只有“tsconfig.json”,没有“tsconfig.app.json”。并且只有“compilerOptions”,而不是“angularCompilerOptions”。仍然添加并得到“enableIvy 不是有效选项。” (3认同)

小智 6

我有错误:

Unknown arguments: use-program-dependencies, useProgramDependencies
An unhandled exception occurred: NGCC failed.
See "C:\...\angular-errors.log" for further details.
Run Code Online (Sandbox Code Playgroud)

我刚刚更新了项目所需的 angular cli、material 和 core 以及其他模块,然后更新了 npm 和 typescript 包,仅此而已。

ng update @angular/cli @angular/core
npm update @angular/material @angular/cdk
npm install -g typescript@latest
Run Code Online (Sandbox Code Playgroud)


ric*_*hul 5

在我的特殊情况下,@angular-devkit/build-angular 在运行 npm 审计修复后在我的 package.json 中更新为“^0.1002.0”。(这个版本好像属于angular 10,而不是本地项目的angular版本(v9.1.3))

恢复此更改后,一切又开始工作:

“@angular-devkit/build-angular”:“~0.901.12”