angular-cli: CLI10: got a few compiler crashes today with "JavaScript heap out of memory"

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was Angular 9 with CLI 9.

Description

Small project freshly migrated from ng9 to 10, I sometimes get a compiler crash with “JavaScript heap out of memory” during ng serve. It never happened to me before ng 10.

Project is available here: https://github.com/ldex/Angular-Academy-202

🔥 Exception or Error


<--- Last few GCs --->

[1308:00000253CB798AB0] 11379648 ms: Scavenge 2033.1 (2051.3) -> 2032.1 (2051.3) MB, 5.4 / 0.0 ms  (average mu = 0.125, current mu = 0.067) allocation failure
[1308:00000253CB798AB0] 11379665 ms: Scavenge 2033.1 (2051.3) -> 2032.2 (2051.3) MB, 8.2 / 0.1 ms  (average mu = 0.125, current mu = 0.067) allocation failure
[1308:00000253CB798AB0] 11379824 ms: Scavenge 2033.5 (2051.6) -> 2032.6 (2051.6) MB, 5.4 / 0.0 ms  (average mu = 0.125, current mu = 0.067) allocation failure

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 00007FF6513377DD]
    1: StubFrame [pc: 00007FF6513388D3]
Security context: 0x00c2be6408d1 <JSObject>
    2: formatLocation(aka formatLocation) [00000377970C75D1] [C:\Users\beep\Desktop\DemoApp\node_modules\webpack\lib\formatLocation.js:~41] [pc=000001471AADB4D8](this=0x012e6a0404b1 <undefined>,0x002fb6ac6cd1 
SourceLocation map = 00    3: /* anonymous */(aka /* anonymous */) [000003C749112FE1] [C

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF65072470F napi_wrap+113583
 2: 00007FF6506CF7D6 v8::base::CPU::has_sse+66646
 3: 00007FF6506D05D6 v8::base::CPU::has_sse+70230
 4: 00007FF650EE42EE v8::Isolate::ReportExternalAllocationLimitReached+94
 5: 00007FF650ECC3C1 v8::SharedArrayBuffer::Externalize+833
 6: 00007FF650D9890C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436 7: 00007FF650DA3B40 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
 8: 00007FF650DA0664 v8::internal::Heap::PageFlagsAreConsistent+3204
 9: 00007FF650D95E63 v8::internal::Heap::CollectGarbage+1283
10: 00007FF650D944D4 v8::internal::Heap::AddRetainedMap+2452
11: 00007FF650DB56DD v8::internal::Factory::NewFillerObject+61
12: 00007FF650B1BF61 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+1665
13: 00007FF6513377DD v8::internal::SetupIsolateDelegate::SetupHeap+546637
14: 00007FF6513388D3 v8::internal::SetupIsolateDelegate::SetupHeap+550979
15: 000001471AADB4D8

🌍 Your Environment




Angular CLI: 10.0.0
Node: 12.18.0
OS: win32 x64

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

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.0
@angular-devkit/build-angular     0.1000.0
@angular-devkit/build-optimizer   0.1000.0
@angular-devkit/build-webpack     0.1000.0
@angular-devkit/core              10.0.0
@angular-devkit/schematics        10.0.0
@ngtools/webpack                  10.0.0
@schematics/angular               10.0.0
@schematics/update                0.1000.0
rxjs                              6.5.5
typescript                        3.9.5
webpack                           4.43.0

Anything else relevant?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 19
  • Comments: 38 (7 by maintainers)

Most upvoted comments

Quick update: We’ve identified the memory leak in Ivy compiler, and we’re currently working on a fix. It’ll be out in v10.0.2.

For me the issue got solved by changing “target”: “es6” from “target”: “es5” in tsconfig.json. However I do have a question. Will this change work in IE11?. And can we do the change to es6? Will it break anything?

v10.0.2 is out! I’ll close this issue for now. Please open a new issue if you run into other memory issues.

I was able to fix this by downgrading the @angular-devkit package(s) to version 0.803.26 inside package.json

"devDependencies": {
    "@angular-devkit/build-angular": "0.803.26",
    ...
}

(might need to delete or update package-lock.json file too, then update packages using npm install).

Any version above 0.803.26 keeps giving me the “JavaScript heap out of memory” error (on serve or build).

Tested on Angular 8 & 9.

It’s still happening after upgrading to v10.0.1 but Its frequency is a little down on my environment. We still need more effective fixes. cc/ @alan-agius4

Update worked fine for me, after the update the leak seems gone, processes are growing and shrinking again in a “normal” way I guess 😃 Only thing observed, incremental build times are way slower now - like 5 seconds instead of 1 second before…

@mduft After which update did you see to start the incremental rebuild time regression? I am trying to figure out if it’s due to a change in Angular framework or the CLI. Investigating this without a reproduction is practically impossible I’m afraid, so is it possible to share a reproduction?

For anyone still seeing issues, it’s probably caused by the same issue as reported in #18087. This is being addressed in #18089 that’s expected to be in the next release, which should be released over the course of today.

For people using Yarn, you can add a "resolutions" block to force copy-webpack-plugin to 6.0.3 however this must then be removed when upgrading to the next release, as it could introduce compatibility issues in the future.

try running node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng serve

or node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng build

@PPInfy, sorry I missed a 0 in my above comment. (Which I edited)

@alan-agius4 I thought since the issue is open and based on your comment this will come in release 10.1.0 to be precise.

@PPInfy, the fix is was referring too, is included in 10.0.1.

@lacolaco, we’ll still continue looking at other possible issues and resolutions.

Nb: using an older version of build-angular might cause undefined behaviour. Angular and Angular CLI version 10 needs @angular-devkit/build-angular version 0.1000.0 or later, using incompatible version is consider unsupported.