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.
i've been able to repro this with a minimal test case using an out-of-the-box cli app; relevant file here.
basically it seems like trying to match a wildcard without specifiers will blow up the app, which is weird since the test case is pulled almost directly from typescript documentation.
note that "*": ["*"] does not crash the app, only "*": ["*", "$dir/*"]
as a workaround, i've manually specified each of my path maps, which is annoying but lets me compile:
"paths": {
"app.*": ["app/app.*"],
"app-*": ["app/app-*"],
"authentication/*": ["app/authentication/*"],
"core/*": ["app/core/*"],
"navigation/*": ["app/navigation/*"],
"pages/*": ["app/pages/*"]
}
We also hit that issue in NativeScript when using the @ngtools/webpack plugin with nativescript-dev-webpack. We use tsconfig paths for mapping our tns-core-modules. They look like that:
"paths": {
"*": [
"./node_modules/*",
"./node_modules/tns-core-modules/*"
]
}
However, the bundling fails with the mentioned error (JavaScript heap out of memory). Just like @zackschuster , as a workaround we specified each path mapping manually:
"paths": {
"application": ["node_modules/tns-core-modules/application"],
"application-settings": ["node_modules/tns-core-modules/application-settings"],
"camera": ["node_modules/tns-core-modules/camera"],
"color": ["node_modules/tns-core-modules/color"],
"connectivity": ["node_modules/tns-core-modules/connectivity"],
"console": ["node_modules/tns-core-modules/console"],
"data/*": ["node_modules/tns-core-modules/data/*"],
"fetch": ["node_modules/tns-core-modules/fetch"],
"file-system": ["node_modules/tns-core-modules/file-system"],
"fps-meter": ["node_modules/tns-core-modules/fps-meter"],
"globals": ["node_modules/tns-core-modules/globals"],
"http": ["node_modules/tns-core-modules/http"],
"image-asset": ["node_modules/tns-core-modules/image-asset"],
"image-source": ["node_modules/tns-core-modules/image-source"],
"location": ["node_modules/tns-core-modules/location"],
"platform": ["node_modules/tns-core-modules/platform"],
"text": ["node_modules/tns-core-modules/text"],
"timer": ["node_modules/tns-core-modules/timer"],
"trace": ["node_modules/tns-core-modules/trace"],
"ui/*": ["node_modules/tns-core-modules/ui/*"],
"utils/*": ["node_modules/tns-core-modules/utils/*"],
"xhr": ["node_modules/tns-core-modules/xhr"],
"xml": ["node_modules/tns-core-modules/xml"]
}
@sis0k0 what do your recompile times look like with that setup? i was getting 40-50s recompiles (on an absurdly tiny project) until i dropped the path maps, at which point it dropped to ~2s.
@zackschuster What do you mean by path maps?
@zigzag95
"paths": {
// ...
}
@zackschuster, similar times.
https://github.com/angular/angular-cli/issues/5618#issuecomment-304545043
I tried the increase-memory-limit package, and I still get Javascript heap out of memory
Still a problem on 4.2.6, macOS, even when giving 8GB to node.
This is a pretty serious problem... it's time to fix this.
It's time to fix this !!! In real big project angular is bad because of that ! Maybe webpack problem !! Thanks
I wonder if the solution is to AOT per module, then a separate link-step? Not sure if it's even possible to implement... In that case, what is lost in global opts, needs to be reclaimed in an LTO.
Still nothing on this?
I am using @angular/cli 1.0.0-rc.4, if I upgrade to 1.0.0 it gives me the error of angular cli FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Now we understand why Google don't use webpack with ng for its apps
Work Around Fix
I was able to fix the issue by changing my ng.cmd file to
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" --max_old_space_size=8192 "%~dp0\node_modules\@angular\cli\bin\ng" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=8192 "%~dp0\node_modules\@angular\cli\bin\ng" %*
)
@cimachris this is not exactly a fix but rather a workaround that can possibly postpone the problem
Is that better?
@hansl @filipesilva I am not able to upgrade my application to angular/cli 1.0.0, since I am at angular/cli 1.0.0.rc-4, don't want to make the jump to the latest version without testing my components
@cimachris we're well beyond the "--max_old_space_size" trick working anymore. Once the app gets large enough, aot builds are impossible due to this problem. Granted, we're an extreme case, because we have lots and lots of generated components (based on screen-scraped definitions of a legacy system), but it should still build of course. This is a very serious bug IMO.
Have been affected by this issue since @angular/cli 1.0 was released But currently we are able to workaround it by running ng build --aot --sourcemaps=false --environment=prod
It's not exactly the same as the --prod parameter but at least it works.
ng e2e also results in a similar error:
92% chunk asset optimization
<--- Last few GCs --->
[2164:000002C715EFDC90] 117246 ms: Mark-sweep 1401.4 (1543.7) -> 1401.3 (1545.7) MB, 1088.0 / 0.0 ms allocation failure GC in old space requested
[2164:000002C715EFDC90] 118473 ms: Mark-sweep 1401.3 (1545.7) -> 1401.2 (1504.2) MB, 1227.0 / 0.0 ms last resort
[2164:000002C715EFDC90] 119591 ms: Mark-sweep 1401.2 (1504.2) -> 1401.1 (1504.2) MB, 1117.8 / 0.0 ms last resort
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 000000799D9A66A1 <JS Object>
2: addMapping(aka SourceMapGenerator_addMapping) [xxx\node_modules\source-map\lib\source-map-generator.js:~94] [pc=0000003D3772300C](this=0000022DE262CAF1 <a SourceMapGenerator with map 000000A8E17906F1>,aArgs=0000005D8F791BF9 <an Object with map 00000399007FF561>)
3: /* anonymous */ [xxx\node_modules\source-map\l...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
@filipesilva This is pretty serious and the workaround does not allways work - it seems to affect all medium/large projects. Needs solved for angular + angularcli to remain a viable technology for serious web projects.