Reputation: 31
Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory, after upgrading an application to Angular 10, it started giving an error of JavaScript heap out of memory. Can someone please advise. Tried multiple ways to increase the memory but didn't get resolve. Thanks!
Upvotes: 1
Views: 2973
Reputation: 654
First things first: which node version are you using? You should use v10.x or v12.x, according to compatibility informations. I've seen some weird errors happening from using node v8.x with new Angular versions.
With this said, in the project I work on (massive project with 500+ components and 190+ modules, with a lot of problems in module hierarchy) we've had to change our build scripts to increase node memory. It can be done in your package.json file:
// package.json file
"scripts": {
"build": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng build",
"postinstall": "ngcc --properties es2015 es5 browser module main --first-only --create-ivy-entry-points"
},
You'll notice the postinstall script. It's a good idea to use it, as since Angular v9, the new Ivy compiler is the default for projects, but not for libraries. This implies the use of the compatibility compiler (ngcc), which will process all Angular libraries. The postscript will run ngcc after npm install, instead of running it at build time.
Cheers!
Upvotes: 2