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

@mhevery @bradlygreen - apologies for pulling you into this one, but with @Tolitech's extreme case above, the value proposition of Angular is starting to become seriously undermined.

Our codebase is growing rapidly, and our team is continuously running into these memory issues, where we even reach the limitations of our development and build machines. In all my years of web development there's never been a case that I would run out of the capabilities of the machine, just to compile to several 300k files for my webapp/website. It seems to be a memory optimization or architectural issue that hopefully can be avoided.

We've already lost countless hours on these problems, and the premise that Angular is a framework that scales for large enterprise applications doesn't hold up anymore.

I'd really appreciate if this issue could be prioritized, as I'm really starting to doubt whether our choice of Angular as a suitable framework was correct, considering that only the AOT builds are performant and small enough to ship to customers over the wire, and that we're struggling to get those to work. Thank you.

bgever avatar Sep 01 '17 05:09 bgever

@bgever Apparently google is not using angular-cli/webpack themselves, so they don't run into problems like this. I suspect this is why this problem receives so little attention from the angular developers. If this continues, the community should be publicly warned about angular being unsuitable for large projects.

xnnkmd avatar Sep 01 '17 05:09 xnnkmd

You were perfect in your words, @bgever . I'm already thinking that Angular does not work for large applications, after all I'm now needing 28 Gb of RAM and the project could grow bigger. (This is the first day of this application).

I'm already thinking about another strategy for this type of project, maybe even change technology because I'm realizing that this problem is occurring with many people and for a long time.

I believe my customer will not accept me saying that he needs 28 Gb RAM to compile his own project. I'm very worried about this.

eduardotolino avatar Sep 01 '17 08:09 eduardotolino

I'm just staying in Angular CLI 1.2.7 while they fix this, hope they do it soon tho, but with 1.2.7 I have no memory problems at all.

Dunos avatar Sep 01 '17 09:09 Dunos

Same here. Running Angular CLI 1.3.2 and Angular 4.3.6. Added this based on another thread to get it to work. My app isn't very big but CLI clocked in at 4GB to build my app.

"scripts": {
    "build": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --target production --environment prod --aot",
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

bjornharvold avatar Sep 07 '17 17:09 bjornharvold

@bjornharvold @Tolitech We need 1024go ram 32ghz cpu, so 32'000'000'000 calcul per second to build angular but if you learn bazel from google it can be faster 😂

elvisbegovic avatar Sep 07 '17 18:09 elvisbegovic

https://github.com/endel/increase-memory-limit

This worked for me

gtarun avatar Sep 08 '17 10:09 gtarun

Same problem here.

I had to downgrade to @angular/cli 1.2.6 with TS 2.4.2 for the build to work again.

A shame I can't use the latest angular cli ... Why isn't this considered a severe bug ?

hugodes avatar Sep 14 '17 08:09 hugodes

@hugodes

Why isn't this considered a severe bug ?

I think it is because of https://github.com/angular/angular/issues/19058

alexzuza avatar Sep 14 '17 08:09 alexzuza

selection_002 Lastest version is the same !

phamtuananh791994 avatar Sep 28 '17 07:09 phamtuananh791994

Same here, this is ridiculous. I'm using a cheap VPS server to build and it simply crashes with 2GB of memory

DutchKevv avatar Sep 28 '17 14:09 DutchKevv

What solved it for me was doing ng build --prod instead of ng build --aot --prod.

The --prod option already includes the --aot one, and optimises the build process and I'm not getting memory errors any more.

Hope it helps some of you guys.

hugodes avatar Sep 28 '17 14:09 hugodes

Try -sm false

aminebizid avatar Sep 28 '17 14:09 aminebizid

It happens to me when the allowJS parameter is true in tsconfig.json. Apparently, the javascript files are overloading the memory.

jota0222 avatar Oct 06 '17 22:10 jota0222

This worked for me, add to package.json scripts section. Watching the memory usage in task manager it got up to around 4gb usage. Seems a touch excessive!

"build2": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod --aot"

npm run build2

clevagroup avatar Oct 10 '17 18:10 clevagroup

This command works for me: node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build --prod

"scripts":{ "prod": "node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build --prod" }

tupham avatar Oct 14 '17 14:10 tupham

try process.nextTick() ?

tossp avatar Oct 23 '17 09:10 tossp

With Node 8.x and latest cli version works without any hack :)

marcalj avatar Oct 23 '17 10:10 marcalj

Sad to see that months have passed and this issue is still not solved. I'm having the same problem here:

´ ng build --aot

92% chunk asset optimization <--- Last few GCs --->

191455 ms: Mark-sweep 1296.7 (1433.7) -> 1291.4 (1434.7) MB, 1052.3 / 0.0 ms [allocation failure] [GC in old space request ed]. 192605 ms: Mark-sweep 1291.4 (1434.7) -> 1291.4 (1434.7) MB, 1150.6 / 0.0 ms [allocation failure] [GC in old space request ed]. 193711 ms: Mark-sweep 1291.4 (1434.7) -> 1294.8 (1403.7) MB, 1105.0 / 0.0 ms [last resort gc]. 194808 ms: Mark-sweep 1294.8 (1403.7) -> 1298.3 (1403.7) MB, 1097.0 / 0.0 ms [last resort gc].

<--- JS stacktrace --->

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

Security context: 00000146E3DCF791 2: addMapping(aka SourceMapGenerator_addMapping) [D:\Users \andre.marcondes\projects\lender-platform\node_modules\source- map\lib\source-map-generator.js:~94] [pc=00000339B436339E] (th is=0000015776039641 <a SourceMapGenerator with map 00000102C1F AA599>,aArgs=00000004C17F22D1 <an Object with map 00000194E061 0DD9>) 3: /* anonymous */ [D:\Users\andre.marcondes\projects\lend er-platform\node...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScrip t heap out of memory ´

andremarcondesteixeira avatar Oct 23 '17 17:10 andremarcondesteixeira

I think this issue can be closed. Not because it's fixed, but because it will NOT be fixed. Not ever.

Google is busy trying to get a Bazel-based build system in place for public consumption, and they are unlikely to spend time fixing this old crap (it's mostly webpack's fault anyway)

ghost avatar Oct 23 '17 17:10 ghost