Allocation failed - JavaScript heap out of memory in Angular 11 while ng serve

Viewed 11454
  1. I have upgraded my Angular version from 5.2 to 11.2
  2. And after upgrading Angular & all library when i start server (ng serve) getting Allocation failed - JavaScript heap out of memory
  3. It also generates 1 file which has information, but i didn't get

can you please help me out of this.

enter image description here

enter image description here

  1. Angular version & details enter image description here

enter image description here

3 Answers

Set an environment variable:

SET NODE_OPTIONS=--max_old_space_size=8048

I found this error comes from the generation of source maps. Disabling source maps will make the error go away.

Since most need source maps, using the solution for increase memory in npm scripts instead of disabling source maps, solves it.

example:

scripts: {
  "build": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build",
  "serve": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve"
}

You can allocate more memory for your build/start task in order to compile:

node --max_old_space_size=4096 ./node_modules/.bin/ng build

And, according to an answer to this question: "export 'DOCUMENT' was not found in '@angular/platform-browser', DOCUMENT has been moved to @angular/common. So you also have to change your imports for your code to compile.

Related