Search code examples
javascriptangularout-of-memoryheap-memoryangular2-aot

Angular 2 - Build with AOT : Javascript heap out of memory


I am developing an angular2 project. I run below command to build AOT package.

ng build --aot --prod

but it returns errors:

 68% building modules 1135/1172 modules 37 active ...cy/node_modules/rxjs/operator/last.js
    <--- Last few GCs --->

    [15184:0x2c46890]    91090 ms: Mark-sweep 1363.5 (1447.6) -> 1363.5 (1447.6) MB, 717.9 / 0.0 ms  allocation failure GC in old space requested
        [15184:0x2c46890]    91834 ms: Mark-sweep 1363.5 (1447.6) -> 1363.6 (1431.6) MB, 742.9 / 0.0 ms  last resort GC in old space requested
        [15184:0x2c46890]    92632 ms: Mark-sweep 1363.6 (1431.6) -> 1363.5 (1431.6) MB, 798.3 / 0.0 ms  last resort GC in old space requested


    <--- JS stacktrace --->

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

    0: ExitFrame [pc: 0x378f8390427d]
    Security context: 0x2cc5da1206a9 <JSObject>
    1: symbolToParameterDeclaration(aka symbolToParameterDeclaration) [/home/mahmood/WebProjects/bisphone-beta-web-lucy/node_modules/typescript/lib/typescript.js:~26179] [pc=0x378f84af538f](this=0x344d038022e1 <undefined>,parameterSymbol=0x1445395f60c1 <SymbolObject map = 0x2b2a3dd2ab11>,context=0x3631eda341b1 <Object map = 0x2b2a3dd51b71>)
    2: signatureT...

    FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
    1: node::Abort() [ng]
    2: 0x88050c [ng]
    3: v8::Utils::ReportOOMFailure(char const*, bool) [ng]
    4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [ng]
    5: v8::internal::Factory::NewLoadHandler(int) [ng]
    6: v8::internal::LoadHandler::LoadFromPrototype(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::Smi>, v8::internal::MaybeHandle<v8::internal::Object>, v8::internal::MaybeHandle<v8::internal::Object>) [ng]
    7: v8::internal::LoadIC::ComputeHandler(v8::internal::LookupIterator*) [ng]
    8: v8::internal::LoadIC::UpdateCaches(v8::internal::LookupIterator*) [ng]
    9: v8::internal::LoadIC::Load(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>) [ng]
    10: v8::internal::Runtime_LoadIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [ng]
    11: 0x378f8390427d
    Aborted (core dumped)
    npm ERR! code ELIFECYCLE
    npm ERR! errno 134
    npm ERR! [email protected] build: `ng build --aot --prod`
    npm ERR! Exit status 134
    npm ERR!
    npm ERR! Failed at the [email protected] build script.
        npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I searched for solution and I found two similar problem in failed - JavaScript heap out of memory” and Angular 2 AOT build error - JavaScript heap out of memory.

Following these posts, add add --max-old-space-size=9000 property but the result changed:

69% building modules 1689/1690 modules 1 active .../@firebase/database/dist/index.cjs.js

#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
#
#
#FailureMessage Object: 0x7f6efe578980Illegal instruction (core dumped)

The project is not very large and it built successfully some days ago. And ng build without --aot --prod works.


Solution

  • By Updating typecript form 2.6.x to 2.7.x problem has been fixed.