Skip to content

ng build causes out of memory #19526

@vicatcu

Description

@vicatcu

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, this started happening when I migrated our server from Angular 9 to Angular 11, and from Node 10 to Node 14.

Description

When I run ng build on my server, during the Generating browser application bundles (phase: building)... message, eventually I get an out of memory crash. This actually happens on my server, which has 2GB or RAM, as well as on my development machine, which has 16GB of RAM.

🔥 Exception or Error

<--- Last few GCs --->

[23183:0x6323910]   114992 ms: Scavenge (reduce) 2029.0 (2046.3) -> 2028.2 (2047.5) MB, 5.6 / 0.0 ms  (average mu = 0.259, current mu = 0.247) allocation failure 
[23183:0x6323910]   115058 ms: Scavenge (reduce) 2029.3 (2046.8) -> 2028.5 (2047.8) MB, 5.2 / 0.0 ms  (average mu = 0.259, current mu = 0.247) allocation failure 
[23183:0x6323910]   115100 ms: Scavenge (reduce) 2029.6 (2046.8) -> 2028.8 (2047.8) MB, 5.1 / 0.0 ms  (average mu = 0.259, current mu = 0.247) allocation failure 


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xa03530 node::Abort() [ng build]
 2: 0x94e471 node::FatalError(char const*, char const*) [ng build]
 3: 0xb7773e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ng build]
 4: 0xb77ab7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ng build]
 5: 0xd32345  [ng build]
 6: 0xd32ecf  [ng build]
 7: 0xd40f5b v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng build]
 8: 0xd44b1c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ng build]
 9: 0xd131fb v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [ng build]
10: 0x10592f0 v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [ng build]
11: 0x13ff179  [ng build]
Aborted

🌍 Your Environment

Angular CLI: 11.0.2
Node: 14.15.1
OS: linux x64

Angular: 11.0.2
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1100.2
@angular-devkit/build-angular   0.1100.2
@angular-devkit/core            11.0.2
@angular-devkit/schematics      11.0.2
@angular/cdk                    11.0.1
@angular/material               11.0.1
@schematics/angular             9.1.7
@schematics/update              0.1100.2
rxjs                            6.5.3
typescript                      4.0.5

Anything else relevant?
Possibly related to #18398, but I'm not sure how to confirm. I don't think I'm using i18n but I think I am targeting es5.

It doesn't crash if I do node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions