angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

AOT build fails due to "JavaScript heap out of memory"

Open ghost opened this issue 9 years ago • 427 comments

Bug Report or Feature Request (mark with an x)

- [X ] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.0
node: 7.7.4
os: win32 x64
@angular/animations: 4.0.0
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.0

Repro steps.

ng build --prod --aot

The log given by the failure.

/node_modules/@angular/material/aut 92% chunk asset optimization
<--- Last few GCs --->

[6328:0000016AB4D09F00]  1775597 ms: Mark-sweep 1411.2 (1513.5) -> 1411.0 (1513.5) MB, 1240.6 / 0.0 ms  last resort


<--- JS stacktrace --->

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

Security context: 0000034B0DD266A1 <JS Object>
    2: optimize [0000000FABC02311 <undefined>:5480] [pc=00000082575652C8](this=000000633199A279 <an AST_Call with map 0000014753FA0291>,compressor=00000226DBDECA61 <a Compressor with map 0000032B1EC8F829>)
    3: before [0000000FABC02311 <undefined>:5463] [pc=0000008258C1818D](this=00000226DBDECA61 <a Compressor with map 0000032B1EC8F829>,node=000000633199A279 <an AST_Call with map 0000014753...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

Desired functionality.

I would like to be able the app using AOT.

Mention any other details that might be useful.

I have tried changing ng.cmd to this:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe" --max_old_space_size=8192 "%~dp0\..\@angular\cli\bin\ng" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node --max_old_space_size=8192 "%~dp0\..\@angular\cli\bin\ng" %*
)

and ngc.cmd to:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe" --max_old_space_size=8192 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node --max_old_space_size=8192 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
)

I have 8GB swap file. The build fails after 20-25 minutes standing on 92% progress.

ghost avatar Mar 24 '17 09:03 ghost

@filipesilva I saw a new version of webpack has been release days ago which ships your performance tuning code, when will angular-cli release a new version refer to the latest version of webpack? Thank you.

alvachien avatar Dec 04 '17 07:12 alvachien

@alvachien In next version of Angular CLI, 1.5.6 or 1.6.0, is what he said just a little up in this thread.

Judging by latest releases I would assume that this could happen this week unless there is something in particular blocking it.

Koslun avatar Dec 04 '17 10:12 Koslun

@kisdaniel 's solution/workaround seems to work fine. its sorted my issues

connorsleight avatar Dec 04 '17 12:12 connorsleight

Increasing --max_old_space_size works for me, but after an hour or so, my RAM (32Gb) usage hits 70% or 80%, incremental builds slow down, and node or ng serve crashes.

wolfhoundjesse avatar Dec 04 '17 14:12 wolfhoundjesse

@wolfhoundjesse are you using AOT on rebuilds?

filipesilva avatar Dec 04 '17 14:12 filipesilva

Is there any ETA on release with aforementioned deps update? Fighting with this issue in our CI which doesn't have much RAM for now, so this fix is urgently required (I know I can hack package.json to point directly at master, but this is a hack I want to avoid).

krassx avatar Dec 04 '17 15:12 krassx

It should be in this weeks release, since we usually release once per week.

filipesilva avatar Dec 04 '17 15:12 filipesilva

@krassx for now, try @kisdaniel 's fix, works fine for an 8gb ram machine

connorsleight avatar Dec 04 '17 15:12 connorsleight

@mast3rd3mon, It doesn't help that much as we have 4GB RAM on our build machine. Will try to play with the limit to make it work.

krassx avatar Dec 04 '17 16:12 krassx

@krassx maybe try the same command but for 4gb ram? so 4096 not 8192

connorsleight avatar Dec 04 '17 16:12 connorsleight

Tried that. And got that out of memory error. It does work on my local machine (macOS, 8GM RAM) but fails on build machine (Linux, 4GB).

krassx avatar Dec 04 '17 16:12 krassx

@krassx try disable build optimizer and source map, can u share yours build command?

WandererInVoids avatar Dec 04 '17 16:12 WandererInVoids

node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --target=production --aot --output-hashing=bundles --build-optimizer=true

This is what I use locally with no errors. But it fails on CI machine as I noted before.

krassx avatar Dec 04 '17 17:12 krassx

@krassx try this for production u can just use prod node --max_old_space_size=4096 --stack_size=512 ./node_modules/@angular/cli/bin/ng build --prod -vc --build-optimizer=false refer to this page for more option https://github.com/angular/angular-cli/wiki/build

WandererInVoids avatar Dec 04 '17 17:12 WandererInVoids

Ok, will give it a try. Thank you.

krassx avatar Dec 04 '17 17:12 krassx

@WandererInVoids, disabling build optimizer did the trick. Thank you for the advice.

krassx avatar Dec 04 '17 18:12 krassx

@krassx your welcome

WandererInVoids avatar Dec 04 '17 19:12 WandererInVoids

@angular/[email protected] is now released and includes the memory fix on Webpack's side.

filipesilva avatar Dec 05 '17 18:12 filipesilva

@filipesilva I'm using node --max_old_space_size=16384 node_modules/.bin/ng serve --aot. I'll upgrade to rc.2 now.

wolfhoundjesse avatar Dec 05 '17 18:12 wolfhoundjesse

@filipesilva I am sorry , I am traveling and missed your question to me. To reply, yes, my problems started after updating to 1.5.0 and plain ng build --prod failed with any 1.5.x. I had to build, as many others, with raised memory node --max-old-space-size=8192 node_modules\@angular\cli\bin\ng build --prod.

Having said that at the same time as I updated to 1.5 I included 3rd party library that probably sent the build process over the edge.

And now the good news. I have just updated to 1.6 and the build finishes just fine with plain old ng build --prod.

Thanks.

PeS82 avatar Dec 07 '17 16:12 PeS82