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.
Under cli1.5 & angular5
Ng build —prod : YES Ng serve —aot : first time NO but after editing file YES it throw error out of memory... blockin at 0%
Ng serve : NO all’s okay and fast (but wait a lot to show result in browser because of JiT compiler)
Cc @filipesilva
The versions I am using CLI - 1.2.0 and Angular 4.2.5 Modules: ~ 130 Components: ~ 200 Services: ~ 70
getting the build issues with below options.
ng build --prod: fail ng build --aot=true: fail ng build --aot=true --sourcemaps=false : Works most of the times and very often it is failing. ng build --prod --aot=false : works
@cecotw sarcasm is sometimes misinterpreted. And I'm not here to fire up any flamewars, your ecosystem is obviously the better :)
I had experienced the issue FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory with ng build --prod. I have solved the problem by using
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod
You can add also in
package.json
as
"scripts": {
"prod": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod",
}
npm run prod
What version of the CLI and Angular are you on?
Angular CLI: 1.5.0
Node: 8.5.0
OS: darwin x64
Angular: 5.0.0
... animations, common, compiler, core, forms, http
... platform-browser, platform-browser-dynamic, router
@angular/cdk: 5.0.0-rc0
@angular/cli: 1.5.0
@angular/compiler-cli: 5.0.1
@angular/flex-layout: 2.0.0-beta.10
@angular/language-service: 5.0.1
@angular/material: 5.0.0-rc0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.2
typescript: 2.4.2
webpack: 3.8.1
Does this only happen on ng build --prod? NOT SURE Do you still get the memory error with these build commands:
- ng build --build-optimizer=false WORKS
- ng build --aot FAILS
- ng build --aot --build-optimizer FAILS
also:
- ng build --aot=true --sourcemaps=false WORKS
- ng build --prod -sourcemaps=false FAILS
- ng build --prod FAILS
- ng build --prod --aot=flase --sourcemaps=false FAILS
If you have a project that I can look at, can you link it please?
- https://github.com/Alfresco/alfresco-ng2-components/tree/development
we have a gitter channel if you need help to build our project and have a look:
- https://gitter.im/Alfresco/alfresco-ng2-components
Same issue. Upgraded to A5. ng build --prod results in out of memory error below. The error does not occur without --prod. Increasing the --max_old_space_size is not really the answer, something is fundamentally wrong and has stopped our A5 upgrade going anywhere.
Please fix!
<--- Last few GCs --->
243344 ms: Mark-sweep 1000.9 (1434.4) -> 1003.2 (1434.4) MB, 452.4 / 0.0 ms [allocation failure] [scavenge might not succeed]. 243760 ms: Mark-sweep 1003.2 (1434.4) -> 1003.2 (1434.4) MB, 416.3 / 0.0 ms [allocation failure] [scavenge might not succeed]. 244187 ms: Mark-sweep 1003.2 (1434.4) -> 1012.9 (1418.4) MB, 427.0 / 0.0 ms [last resort gc]. 244591 ms: Mark-sweep 1012.9 (1418.4) -> 1022.8 (1418.4) MB, 403.8 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x957966cfb39
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node::Abort() [/usr/local/bin/node] 2: node::FatalException(v8::Isolate*, v8::Localv8::Value, v8::Localv8::Message) [/usr/local/bin/node] 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node] 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node] 5: v8::internal::Runtime_StringBuilderJoin(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node] 6: 0xbe4066092a7 Abort trap: 6
What version of the CLI and Angular are you on?
@angular/cli: 1.4.9
node: 6.11.0
os: win32 x64
@angular/animations: 4.4.6
@angular/cdk: 2.0.0-beta.12
@angular/common: 4.4.6
@angular/compiler: 4.4.6
@angular/core: 4.4.6
@angular/flex-layout: 2.0.0-beta.9
@angular/forms: 4.4.6
@angular/http: 4.4.6
@angular/material: 2.0.0-beta.12
@angular/platform-browser: 4.4.6
@angular/platform-browser-dynamic: 4.4.6
@angular/router: 4.4.6
@angular/cli: 1.4.9
@angular/compiler-cli: 4.4.6
typescript: 2.6.1
ng build --prod - Success
ng build --build-optimizer=false - Success
ng build --aot - Success
ng build --aot --build-optimizer - OOME
A sanity-check local run of ng serve --prod --aot gave me failure at a later time
Date: 2017-11-12T22:52:55.879Z
Hash: 456f57f84be9de32704e
Time: 185523ms
chunk {0} polyfills.5dbd24b37bdff70c0320.bundle.js (polyfills) 66.1 kB {4} [initial] [rendered]
chunk {1} main.a2ba9af755957e20aa31.bundle.js (main) 1.98 MB {3} [initial] [rendered]
chunk {2} styles.2dfc00976daefa57d973.bundle.css (styles) 80.3 kB {4} [initial][rendered]
chunk {3} vendor.c5146d2ca93aff011cac.bundle.js (vendor) 1.51 MB [initial] [rendered]
chunk {4} inline.7e6f8c72074764ba2a48.bundle.js (inline) 1.45 kB [entry] [rendered]
webpack: Compiled successfully.
<--- Last few GCs --->
277448 ms: Mark-sweep 1225.3 (1434.4) -> 1225.3 (1434.4) MB, 1086.6 / 0.1 ms [allocation failure] [scavenge might not succeed].
278456 ms: Mark-sweep 1225.3 (1434.4) -> 1225.3 (1434.4) MB, 1008.4 / 0.1 ms [allocation failure] [scavenge might not succeed].
279488 ms: Mark-sweep 1225.3 (1434.4) -> 1236.2 (1418.4) MB, 1030.8 / 0.1 ms [last resort gc].
280607 ms: Mark-sweep 1236.2 (1418.4) -> 1247.1 (1418.4) MB, 1117.0 / 0.1 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 00000126BFCCFB49 <JS Object>
1: DoJoin(aka DoJoin) [native array.js:~129] [pc=000003FAD779BBD7] (this=00000126BFC04381 <undefined>,w=0000033E0E885D01 <JS Array[334]>,x=334,N=00000126BFC043C1 <true>,J=00000126BFCAE4C9 <String[1]: >,I=00000126BFCB46D9 <JS Function ConvertToString (SharedFunctionInfo 00000126BFC52DC9)>)
2: Join(aka Join) [native array.js:180] [pc=000003FAD73F9FB2] (this=00000126BFC04381 <undefined>...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
In my project everything was working fine in --prod --aot mode up until a day ago when I decided to migrate to HttpClient to prepare for the Angular 5 / CLI 1.5 switch. No version changes, no CLI changes were involved.
I upgraded my services and moved some error/auth logic to a couple of interceptors. My vendor dev bundle went from 15MB to 6MB and I was all impressed. Then I decided to sanity check my prod aot build with ng serve --prod --aot and I started getting the OOME.
Seeing the same issue after upgrading to cli 1.5, Angular 1.5 and HttpClient
$ ng build --aot --prod
95% emitting
<--- Last few GCs --->
224719 ms: Mark-sweep 1304.7 (1434.7) -> 1304.7 (1434.7) MB, 485.6 / 0.0 ms [allocation failure] [scavenge might not succeed]. 225206 ms: Mark-sweep 1304.7 (1434.7) -> 1304.7 (1434.7) MB, 487.0 / 0.0 ms [allocation failure] [scavenge might not succeed]. 225685 ms: Mark-sweep 1304.7 (1434.7) -> 1304.7 (1418.7) MB, 479.3 / 0.0 ms [last resort gc]. 226180 ms: Mark-sweep 1304.7 (1418.7) -> 1304.7 (1418.7) MB, 494.5 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x3e4edad3fa99
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Localv8::Value, v8::Localv8::Message) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
5: v8::internal::Runtime_StringBuilderJoin(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
6: 0xd5ac97060c7
7: 0xd5adf91512e
Abort trap: 6
Jays-MacBook-Pro:ngx-dynamic-dashboard-framework jayhamilton$ ng build --aot --prod
95% emitting
<--- Last few GCs --->
224540 ms: Mark-sweep 1305.3 (1444.7) -> 1305.3 (1444.7) MB, 476.2 / 0.0 ms [allocation failure] [scavenge might not succeed]. 225007 ms: Mark-sweep 1305.3 (1444.7) -> 1305.3 (1444.7) MB, 466.7 / 0.0 ms [allocation failure] [scavenge might not succeed]. 225479 ms: Mark-sweep 1305.3 (1444.7) -> 1305.3 (1428.7) MB, 471.9 / 0.0 ms [last resort gc]. 225970 ms: Mark-sweep 1305.3 (1428.7) -> 1305.3 (1428.7) MB, 491.1 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x67c5bb3fa99
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node::Abort() [/usr/local/bin/node] 2: node::FatalException(v8::Isolate*, v8::Localv8::Value, v8::Localv8::Message) [/usr/local/bin/node] 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node] 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node] 5: v8::internal::Runtime_StringBuilderJoin(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node] 6: 0x33787d0060c7 7: 0x337898eca1ce Abort trap: 6
PACKAGE.JSON "dependencies": { "@angular/animations": "^5.0.1", "@angular/cdk": "2.0.0-beta.12", "@angular/common": "^5.0.1", "@angular/compiler": "^5.0.1", "@angular/core": "^5.0.1", "@angular/forms": "^5.0.1", "@angular/http": "^5.0.1", "@angular/material": "2.0.0-beta.12", "@angular/platform-browser": "^5.0.1", "@angular/platform-browser-dynamic": "^5.0.1", "@angular/router": "^5.0.1", "@swimlane/ngx-charts": "6.1.0", "core-js": "^2.4.1", "d3": "^4.4.0", "jquery": "2.2.0", "ng2-cookies": "1.0.3", "ng2-dnd": "^2.1.1", "reflect-metadata": "0.1.8", "rxjs": "^5.5.2", "semantic-ui": "2.2.2", "socket.io-client": "^1.7.2", "sockjs-client": "^1.1.4", "stompjs": "^2.3.3", "zone.js": "^0.8.4" }, "devDependencies": { "@angular/cli": "1.5.0", "@angular/compiler-cli": "^5.0.1", "@types/jasmine": "2.5.38", "@types/node": "~6.0.60", "codelyzer": "~2.0.0", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~3.2.0", "karma": "~1.4.1", "karma-chrome-launcher": "~2.0.0", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^0.2.0", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.1.0", "ts-node": "~2.0.0", "tslint": "~4.5.0", "typescript": "~2.6.1" }
EDIT working with the --max_old_space_size=8192 fix above**
Also getting the exact same. Angular 4 build time, 2 minutes maybe? New angular 5 build time is 25 to fail with:
ng build --prod --output-path=dist/client
92% chunk asset optimization <--- Last few GCs --->
1327460 ms: Mark-sweep 1306.9 (1405.9) -> 1306.9 (1414.9) MB, 1826.0 / 0.0 ms [allocation failure] [GC in old space requested]. 1329363 ms: Mark-sweep 1306.9 (1414.9) -> 1306.9 (1414.9) MB, 1903.1 / 0.0 ms [allocation failure] [GC in old space requested]. 1331374 ms: Mark-sweep 1306.9 (1414.9) -> 1313.4 (1405.9) MB, 2010.3 / 0.0 ms [last resort gc]. 1333333 ms: Mark-sweep 1313.4 (1405.9) -> 1319.9 (1405.9) MB, 1958.0 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 000002E7514CF791
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Any update on this? This issue was raised back in March and is now manifesting itself in Angular 5 (and 4) prod builds. Seems somehow to be related to HttpClient.
Please can you investigate as a priority as we can not go to production using Angular 5, which is currently not fit for purpose.
@JonathanYates https://github.com/angular/angular-cli/issues/5618#issuecomment-343244854
Yes I know, that was 5 days ago. I am asking for an update.
Same issues, should build app without problems with ng build --prod
@filipesilva: I'm asking for an update date.
@andremarcondesteixeira we will all do what we please. This isn't the place to try to convince anybody to use another framework.
@JonathanYates @MichalEmbiq @andremarcondesteixeira - Have you guys tried what @filipesilva suggested in #5618 (comment)? That seems to have worked for most people and it also worked for me. Seems like a sufficient work-around until the real issue is solved.
@jmcclanahan @filipesilva
ng serve : SUCCESS ng build : SUCCESS
ng build --prod : FAIL ng build --prod --build-optimizer=false : FAIL ng build --aot : FAIL ng build --aot --build-optimizer : FAIL
output as per https://github.com/angular/angular-cli/issues/5618#issuecomment-343765822
It also takes several 'minutes' hung at 92% before producing an error.
How do you suggest I produce a production build?
Hi @filipesilva
-
What version of the CLI and Angular are you on? 1.5
-
Does this only happen on ng build --prod? No, with --aot and --build-optimizer it fails too (see below)
-
Do you still get the memory error with these build commands: For the commands that fail, it can be intermittent - ie. fail 4/5 times, but pass on the 5th ng build --build-optimizer=false: Passes ng build --aot: Passes ng build --aot --build-optimizer: Fails
I can get these to pass 100% of the time by increasing the amount of available memory (ie: node --stack_size=4048 node_modules/.bin/ng build --prod | OR by --build-optimizer=false)
I've created a simple repo of the problem here: https://github.com/seanlandsman/build-optimiser-issue
Steps to reproduce: npm install npm run prod (note: this fails most of the time, but very occasionally it will pass)
thanks
I don't think increasing the node --stack_size is a good idea. All that will do is mask the real issue here. The build should not be gobbling up so much memory. There is a fundamental problem that needs to be fixed.
Think about CI, some environments don't have so much memory. How this "feature" pass tests? Why issue is closed?
- The issue is not "closed". It's both open and marked urgent.
- No one is suggesting that increasing the stack size is a permanent solution
- angular-cli developers have chimed in indicating they're taking the issue seriously and requested feedback on which builds were having issues.
If folks want to complain about memory requirements, they can. If folks want to say it's unreasonable this bug exists, they can. If folks want to encourage people to no longer use Angular, they can. The developers are already looking at this, no amount of vitriol will make that faster. In the mean time, add a swap volume, increase the stack size, and subscribe to the issue for updates -- which unfortunately will likely be mostly complaints for a while.