11
  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

Sam Joshua
  • 310
  • 6
  • 17
Apurv Chaudhary
  • 1,672
  • 3
  • 30
  • 55
  • it depends on your PC memory size, you can add this to your package.json file : `{ ... "start": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng serve", ..}` – sohaieb azaiez May 29 '21 at 13:20
  • @sohaiebazaiez i have tried with that but getting multiple error **"export 'DOCUMENT' (imported as 'i28') was not found in '@angular/platform-browser'** – Apurv Chaudhary May 31 '21 at 14:39
  • When updating, it is usually better to update the versions, one by one... – StPaulis May 31 '21 at 14:42
  • @StPaulis yes, i have upgrade all library one by one & resolve all issues, but when i am trying to compile it gives **javascript heap out of memory** error – Apurv Chaudhary May 31 '21 at 14:49
  • I ment, that you should first update to Angular 6, then Angular 7, then 8... – StPaulis May 31 '21 at 14:52
  • @StPaulis yes, i do same from **https://update.angular.io/** this website, but when i tried with Angular 8 & upgrade all libraries then i get above all errors, – Apurv Chaudhary May 31 '21 at 14:54
  • Do you have the project in a public repository? – Owen Kelvin May 31 '21 at 17:32
  • @OwenKelvin no, it's not public, but i will provide some information, if you want – Apurv Chaudhary Jun 01 '21 at 05:43
  • 1
    @Chaudhary Looks like you have 2 problems: a memory error that you have resolved by adding `--max_old_space_size` and a lot of errors caused by `export 'DOCUMENT'` – Raphaël Jun 01 '21 at 13:02

4 Answers4

10

Set an environment variable:

SET NODE_OPTIONS=--max_old_space_size=8048
  • after set this i am getting some **DOCUMENT** error, which i have added screenshot at last, & also i moved DOCUMENT to @angular/common, but still i am getting error – Apurv Chaudhary Jun 02 '21 at 07:27
8

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"
}
3

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.

Raphaël
  • 3,646
  • 27
  • 28
  • when i set **node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng serve**, i start my server but get compile error, thats come from .ngFctory file, & i already import DOCUMENT from @angular/common – Apurv Chaudhary Jun 02 '21 at 07:09
  • i added screenshot of *DOCUMENT* error, please review. – Apurv Chaudhary Jun 02 '21 at 07:09
1

GIT BASH: ENV NODE_OPTIONS=--max_old_space_size=8048 && ng build

CMD SET NODE_OPTIONS=--max_old_space_size=8048 && ng build

Ankit Aranya
  • 930
  • 1
  • 10
  • 17