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

@edmund-lee

ng build --aot --sourcemaps=false --environment=prod

It's not exactly the same as the --prod parameter but at least it works.

Doesn't work for sufficiently large projects.

ghost avatar Jul 14 '17 11:07 ghost

@angular/cli: 1.2.3 node: 6.10.0 os: linux x64 @angular/animations: 4.3.1 @angular/common: 4.3.1 @angular/compiler: 4.3.1 @angular/core: 4.3.1 @angular/forms: 4.3.1 @angular/http: 4.3.1 @angular/platform-browser: 4.3.1 @angular/platform-browser-dynamic: 4.3.1 @angular/router: 4.3.1 @angular/cli: 1.2.3 @angular/compiler-cli: 4.3.1 @angular/language-service: 4.3.1

App with 3 modules and about 50 components, after switching @angular/cli from 1.1.x to 1.2.x

ng build -target=production

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [@angular/cli]
 2: 0x109bf8c [@angular/cli]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [@angular/cli]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [@angular/cli]
 5: v8::internal::Factory::NewInternalizedStringImpl(v8::internal::Handle<v8::internal::String>, int, unsigned int) [@angular/cli]
 6: v8::internal::StringTable::LookupString(v8::internal::Isolate*, v8::internal::Handle<v8::internal::String>) [@angular/cli]
 7: v8::internal::LookupIterator::PropertyOrElement(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, bool*, v8::internal::LookupIterator::Configuration) [@angular/cli]
 8: v8::internal::Runtime::GetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [@angular/cli]
 9: 0xed3501 [@angular/cli]
10: v8::internal::Runtime_KeyedGetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [@angular/cli]
11: 0x2174585092a7
Aborted (core dumped)

emazv72 avatar Jul 26 '17 10:07 emazv72

root cause analysis:

  • OOM on CI machine ( also after adding --max-old-space-size=4096 to node ) due to broken symlink

After fixing it:

ng build --prod

ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' @ ./src/main.ts 3:0-74 @ multi ./src/main.ts ` Upgraded @angular/cli to 1.2.4, still getting the same error ( yarn )

After looking at #7125 it looked like it was an aot related, package dependency issue. Reverting back to npm fixed it.

emazv72 avatar Jul 26 '17 14:07 emazv72

i've also seen this error pop up when using @ngtools/webpack by itself. interestingly, it doesn't happen until after a few rebuilds, implying there's a huge memory leak somewhere in either webpack (doubtful) or the ngtools plugin.

zackschuster avatar Jul 26 '17 16:07 zackschuster

this is so java :))

RuedigerMoeller avatar Aug 06 '17 02:08 RuedigerMoeller

Same issue. As soon as project gain size this thing happens.

baio avatar Aug 08 '17 14:08 baio

Exact same error here, but with @ngtools/webpack I've tried running it with Node LTS 6.11.2 and Node Latest as well 8.2.1 Tried with Typescript 2.3.2 and 2.4.2. All my angular packages are at 4.3.3

AoT is pretty much necessary for large apps, so it's kinda ironic we can't get it so build for those.

etiennetalbot avatar Aug 08 '17 17:08 etiennetalbot

after update to angular/[email protected] have the same issue.

@angular/cli: 1.3.0 node: 8.2.1 os: darwin x64 @angular/animations: 4.3.3 @angular/common: 4.3.3 @angular/compiler: 4.3.3 @angular/core: 4.3.3 @angular/forms: 4.3.3 @angular/http: 4.3.3 @angular/platform-browser: 4.3.3 @angular/platform-browser-dynamic: 4.3.3 @angular/router: 4.3.3 @angular/cli: 1.3.0 @angular/compiler-cli: 4.3.3

command: ng build -prod --build-optimizer --aot=true --progress=false --sourcemap

amikitevich avatar Aug 10 '17 09:08 amikitevich

Just as a heads up. It turns out when I use YARN instead of NPM to RESTORE packages ng build completes successfully.

I am using

ng build --env=prod --aot

When I restore packages using npm install -- same error from this issue (out of memory) When I restore packages using yarn install -- no error - success

brunobertechini avatar Aug 10 '17 16:08 brunobertechini

Also got this error after updating to @angular/cli 1.3.0.

Problem solved after upgrading typescript both locally and globally to 2.4.2

blyndcide avatar Aug 10 '17 19:08 blyndcide

Also got this error.

Locking @ngtools/webpack to version 1.5.4 helps.

wojciech-wator avatar Aug 11 '17 10:08 wojciech-wator

I had to increase memory given to Node, as well as bump TS to 2.4.2, but after that I did get a successful build. looking forward to NG5 AoT compiler

josephliccini avatar Aug 11 '17 17:08 josephliccini

Same problem here after updating to @angular/cli 1.3.0.

williangd avatar Aug 14 '17 13:08 williangd

@williangd also for me with 1.3.0

ChenReuven avatar Aug 15 '17 05:08 ChenReuven

I've also been getting the out of memory issue when running ng serve. It works fine for hours, but if I've been developing for a while (I've seen it anywhere from 2-5 hours) I will get the out of memory crash. When rerunning the serve command, I can go typically for another 2-5 hours. The first time I saw this was when updating to a beta version of 1.3, but I haven't seen an improvement with the current release.

jloosli avatar Aug 15 '17 14:08 jloosli

For me it also happens with the normal "ng serve" after upgrading to 1.3 version, every time the project recompiles, its takes more time than the previous (6s, 10s, 30s, 60s) and after 4 or 5 times, it goes out of memory.

Dunos avatar Aug 16 '17 10:08 Dunos

Same issue.

95% emitting <--- Last few GCs --->

160332 ms: Mark-sweep 1346.8 (1439.3) -> 1346.7 (1439.3) MB, 648.6 / 0.0 ms [allocation failure] [scavenge might not succeed]. 160934 ms: Mark-sweep 1346.7 (1439.3) -> 1346.8 (1439.3) MB, 602.0 / 0.0 ms [allocation failure] [scavenge might not succeed]. 161564 ms: Mark-sweep 1346.8 (1439.3) -> 1346.8 (1423.3) MB, 629.5 / 0.0 ms [last resort gc]. 162181 ms: Mark-sweep 1346.8 (1423.3) -> 1346.7 (1423.3) MB, 616.9 / 0.0 ms [last resort gc].

<--- JS stacktrace --->

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

Security context: 0000009DB903FA99 1: DoJoin(aka DoJoin) [native array.js:~129] [pc=000000A40AE7FE82] (this=0000009DB9004241 ,w=00000355FBAF7F99 <JS Array[287]>,x=287,N=0000009DB9004281 ,J=0 000009DB904A369 <String[1]: >,I=00000342545B4E81 <JS Function ConvertToString (SharedFunctionInfo 0000009DB905DBC9)>) 2: Join(aka Join) [native array.js:180] [pc=000000A406C83FF2] (this=0000009DB9004241 ...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

tsc -v Version 2.4.2

@angular/cli: 1.3.0 node: 6.11.2 os: win32 x64

AlekBro avatar Aug 17 '17 09:08 AlekBro

How is upgrading to typescript 2.4.2 working. You will get build issues from RxJs as they 2.4 broke the typings of rxjs

sbabeal avatar Aug 18 '17 00:08 sbabeal

This problem is happening as well for our project. Can't build aot on build server with the same javascript heap out of memory. We are also using the experimental webpack 3 support.

sbabeal avatar Aug 18 '17 00:08 sbabeal

@sbabeal just go to RxJS 5.4.2

josephliccini avatar Aug 18 '17 01:08 josephliccini