Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory in angular

try running the build with this

node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve

or other way is to add this to the package.json

"build-serve": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve"

where 8048 is the max heap size.


Issue: While building(compiling), memory exceeds allocated memory for compilation.

Fix: Increase allocation memory. 8192 is the size used in the below script. You can vary this according to your need.

Try to run commands like this:

Serving:

node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve

Building:

node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod

Custom script:

Your script command(as mentioned in comment):

ng serve --aot --proxy-config proxy.conf.json --host 0.0.0.0 --disable-host-check --live-reload --progress

Modify to:

node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --aot --proxy-config proxy.conf.json --host 0.0.0.0 --disable-host-check --live-reload --progress

If you're on older version of NodeJS, then upgrading NodeJS to v12 helps solving this problem.

NodeJS v12 has different heap management strategy, see more info here.