GeezerVison is showing github.com — AOT build fails due to "JavaScript heap out of memory" · Issue #5618 · angular/angular-cli
AOT build fails due to "JavaScript heap out of memory" #5618Description
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. Reacted by iuristona, GQ, Chris Nicola, Fabien Dehopré, Herc, Bart Slootweg, Veselina Radeva, Jason Hodges, Robin Regmi, Ahmad Baktash Hayeri and 148 more Reacted by doomy [archive], Tal Koren, Cristi Anichitei, Gregory Petrosyan, Vlad Dobrescu, Jorge Y. C. Rodriguez, 浩然, Vijay Singh, andrea-spotsoftware, Alessandro Avila and 3 more Reacted by Vijay Singh, Adrian Moisa and Maxime Activityfilipesilva commented on Mar 24, 2017 This is similar to #1652, but seems localized to AOT compilations. There might be improvements we can do to help. iuristona commented on Mar 24, 2017 I got the same issue too.
So, I tried to build the same project (@angular 4.0.0) using ng-cli 1.0.0-rc.4 and it works fine.
ng build --prod --aot
@angular/cli: 1.0.0-rc.4
node: 6.9.5
os: win32 x64
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0-rc.4
@angular/compiler-cli: 4.0.0 Reacted by GQ and Kumaresan tonny008 commented on Mar 27, 2017 I have the same issue. my project works on cli rc.4. it fails when ng build --prod after update to 1.0.0. aminebizid commented on Mar 27, 2017 I'm so afraid there will be no solution for this issue.
I reverted to rc.2 because of this :( efstathiosntonas commented on Mar 28, 2017 In my case, I installed [email protected] instead of @~2.2.0 and the memory issue went away. Give it a try.
There is an issue in ~2.2.0 and @angular/language-service 4.0.0 (in my case i use it) AngelVlc commented on Mar 28, 2017 I've changed max_old_space_size in %AppData%\npm (Windows) and it works for me when launching ng serve with 1.0.0. Reacted by Michael DePouw, shyampatil89 and Daniel Salazar Reacted by Daniel Salazar aminebizid commented on Mar 28, 2017 @efstahiosntonas are you using ng4? efstathiosntonas commented on Mar 28, 2017 elvisbegovic commented on Mar 28, 2017 chrisnicola commented on Mar 28, 2017 I'm getting OOM errors with @ngtools/webpack 1.3.0 and @angular 4.0.0. This is on OSX and not Windows as well.
<--- Last few GCs --->
17671 ms: Mark-sweep 1241.3 (1413.6) -> 1241.3 (1413.6) MB, 615.1 / 0.0 ms [allocation failure] [GC in old space requested].
18286 ms: Mark-sweep 1241.3 (1413.6) -> 1241.3 (1413.6) MB, 614.2 / 0.0 ms [allocation failure] [GC in old space requested].
18897 ms: Mark-sweep 1241.3 (1413.6) -> 1249.0 (1410.6) MB, 610.8 / 0.0 ms [last resort gc].
19484 ms: Mark-sweep 1249.0 (1410.6) -> 1256.6 (1410.6) MB, 586.6 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x51588dcfb51 <JS Object>
1: /* anonymous */ [/Users/chrisnicola/src/wealthbar/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:~28] [pc=0x33d385eb70d4] (this=0xd76ce5e1e71 <a Resolver with map 0x20b5bd9fe3f1>,request=0x3f6f1fa5ec39 <an Object with map 0x1fbc4c2b91c1>,callback=0xfd0ab9f8a9 <JS Function (SharedFunctionInfo 0x395f78d2a061)>)
2: applyPluginsParallelBailResult1 [/Users/chri...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/Cellar/node/6.9.1/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/Cellar/node/6.9.1/bin/node]
3: v8::Utils::ReportApiFailure(char const*, char const*) [/usr/local/Cellar/node/6.9.1/bin/node]
4: v8::Utils::ApiCheck(bool, char const*, char const*) [/usr/local/Cellar/node/6.9.1/bin/node]
5: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/Cellar/node/6.9.1/bin/node]
6: v8::internal::Factory::NewInternalizedStringImpl(v8::internal::Handle<v8::internal::String>, int, unsigned int) [/usr/local/Cellar/node/6.9.1/bin/node]
7: v8::internal::InternalizedStringKey::AsHandle(v8::internal::Isolate*) [/usr/local/Cellar/node/6.9.1/bin/node]
8: v8::internal::StringTable::LookupKey(v8::internal::Isolate*, v8::internal::HashTableKey*) [/usr/local/Cellar/node/6.9.1/bin/node]
9: v8::internal::StringTable::LookupString(v8::internal::Isolate*, v8::internal::Handle<v8::internal::String>) [/usr/local/Cellar/node/6.9.1/bin/node]
10: v8::internal::LookupIterator::LookupIterator(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::LookupIterator::Configuration) [/usr/local/Cellar/node/6.9.1/bin/node]
11: v8::internal::LookupIterator::PropertyOrElement(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>,v8::internal::Handle<v8::internal::Object>, bool*, v8::internal::LookupIterator::Configuration) [/usr/local/Cellar/node/6.9.1/bin/node]
12: v8::internal::Runtime::GetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [/usr/local/Cellar/node/6.9.1/bin/node]
13: v8::internal::Runtime_KeyedGetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/Cellar/node/6.9.1/bin/node]
14: 0x33d384d092a7
[1] 9536 abort npm start
Reacted by monnef and Nicky Kibor Kimaina ImranAhmed commented on Oct 21, 2018 I started seeing this on my Azure DevOps Build server after upgrading to Angular 7.
Adding the following to package.json and then calling this from my build task fixed it.
"build-prod": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --prod
Reacted by Teoman Tuncer, felikf, Eddie Oosthuizen, LosD, Lucas H., Ennio Bozzetti, Nikola Andreev, Mario Mol, Sean G. Wright, Jan Papenbrock and 3 more sanidz commented on Nov 16, 2018 If you have this problem with quagga js library , pay attention that "@angular/service-worker" is installed before "quagga": "^0.12.1" package. mariohmol commented on Nov 19, 2018 i could run with optimizejs using node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build --release --prod --minifyjs --minifycss --optimizejs HarelM commented on Dec 3, 2018 For people who missed @dakotamurphyucf like I did:
using increase-memory-limit package after running npm install will reduce all need to know where binary files are and will do it for all the files - which in my case is very useful since I'm running both regular build and cordova build.
I'm using it only in my CI build script since locally it runs well.
basically: npm install increase-memory-limit -g
And run the command increase-memory-limit.
Pain is gone! No more suffering (for me at least)... marcj commented on Dec 6, 2018 Or just use export NODE_OPTIONS=--max_old_space_size=4096 which should fix it as well. Reacted by Jatinder Kumar and David Hayriyan jatinderkumargupta commented on Dec 10, 2018 @marcj this solution worked for me.
I set NODE_OPTIONS for windows with following command:
set NODE_OPTIONS=--max_old_space_size=4096
Installing increase-memory-limit, did not work for me on windows. I have not tried on linux/ubuntu or other OS. HarelM commented on Dec 10, 2018 @jatinderkumargupta Please note that it's not enough to install increase-memory-limit, you need to run it also after npm installation of all packages has completed. I'm using windows and it worked for me. jatinderkumargupta commented on Dec 10, 2018 Thanks @HarelM, I run that like you mentioned, but it did not work for me. May be some other problem then. pdemro commented on Dec 20, 2018 In Azure Devops I added a command line task which executes the command below prior to the ng build:
node --max-old-space-size=8192
This seems to have resolved the issue for now.. bkarv commented on Dec 23, 2018
"build-prod": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --prod
@ImranAhmed thanks for the suggestion. However where abouts do you add it in angular.json? If I add it I get an 'Property build-prod' not allowed? ImranAhmed commented on Dec 23, 2018 @bkarv
Add it to package.json under the 'scripts' section not angular.json.
If you are facing the issue with your Azure DevOps build you can then call this new script command that you just added from your AzureDevops build task. bkarv commented on Dec 23, 2018 I tried scripts but got errors. I ended up following the suggestion to export NODE_OPTIONS in OS and it worked. Many thanks filipesilva commented on Dec 27, 2018 Hi all,
This thread was opened a while ago, and over time new memory problems have arisen and been solved. Meanwhile a lot of reports still appear here as comments.
Having all the feedback in a single thread makes it hard to get meaningful reports, or to inform people of what versions the regressions that affect them were fixed.
At the time of writing, there are 450 hidden comments:

Having so many hidden comments makes it hard for people to find information in anything but the latest comments. But on the other hand I don't think most people would go through all of the comments anyway. New users that see this thread mostly read the first and latest comments and lose things said in between.
So for the reasons stated above (high volume of comments, hidden comments, hard to report and inform people) I'm also locking this issue to prevent this comment from being lost as new comments come in.
Thank you to everyone that reported and helped diagnose these memory problems. If you encounter any new ones, please open a new issue so we can give that specific regression our full attention and provide a resolution for it.
So I'd like to leave the last comment in this thread as reiterating what I said in #5618 (comment), as I think that is what will help most people that find this issue:
Increasing the memory limit is not a hack, and something you should expect to do at some point. Node processes have a default memory limit of about 1.7gigs. When a node process starts getting close to the memory limit it needs to spend more and more time doing garbage collection to free up memory, which in turn makes it run more slowly.
Bigger projects will use up more memory than smaller projects so at some point a project will hit the memory limit. I personally use a npm script for this:
"ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",
npm scripts scripts go into the package.json file, under the scripts key:
{
"name": "my-project",
"version": "0.0.0",
"scripts": {
"ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
When you use have that script, you can use npm run ng-high-memory -- followed by the arguments instead of ng inside that project. Always use the double dash before arguments, otherwise they might not be parsed correctly. locked as resolved and limited conversation to collaborators on Dec 27, 2018
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|