Angular ng serve produces Error: NGCC failed

Viewed 28476

After running ng serve I've got an exception in terminal window:

Compiling @angular/core : module as esm5

Error: Error on worker #1: TypeError: Cannot read property 'map' of undefined

and message below:

An unhandled exception occurred: NGCC failed.

See /tmp/ng-EAdxWj/angular-errors.log for further details.

angular-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)
4 Answers

Just had the same Issue.

Fixed it by adding following to the tsconfig.app.json:

"angularCompilerOptions": {
    "enableIvy": false
},

Hope this helps

I had the error:

Unknown arguments: use-program-dependencies, useProgramDependencies
An unhandled exception occurred: NGCC failed.
See "C:\...\angular-errors.log" for further details.

I just updated angular cli, material and core, and other modules needed to my project, then updated npm and typescript package, and that's all.

ng update @angular/cli @angular/core
npm update @angular/material @angular/cdk
npm install -g typescript@latest

In my particular case the @angular-devkit/build-angular was updated to "^0.1002.0" in my package.json after running the npm audit fix. (This version seems to belong to angular 10, instead of the local projects' angular version (v9.1.3))

After reverting this change, everything started working again :

"@angular-devkit/build-angular": "~0.901.12"

I have the same Linux setup locally and on a remote server. Locally it works, remotely I had "NGCC failed". Not very informative.

So I started to re-install everything: nodejs, npm, ng. I tried to purge and invalidate caches. Nothing helped.

Then at some point I got:

ENOMEM error thrown after spawn

Which brought me to Node.js catch ENOMEM error thrown after spawn

Indeed my hosting is 1Gb RAM and no swap. So I added it and magically ngcc started to work.

Now I wonder whether swap fixed it or my efforts to re-install everything on the remote server.

Related