AOT build fails due to "JavaScript heap out of memory"
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.
@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 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.
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.
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.
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 @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 😂
https://github.com/endel/increase-memory-limit
This worked for me
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
Why isn't this considered a severe bug ?
I think it is because of https://github.com/angular/angular/issues/19058
Lastest version is the same !
Same here, this is ridiculous. I'm using a cheap VPS server to build and it simply crashes with 2GB of memory
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.
Try -sm false
It happens to me when the allowJS parameter is true in tsconfig.json. Apparently, the javascript files are overloading the memory.
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
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" }
try process.nextTick() ?
With Node 8.x and latest cli version works without any hack :)
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
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScrip t heap out of memory ´
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)