Angular 2-使用AOT进行构建:JavaScript堆内存不足

时间:2018-08-15 07:04:22

标签: javascript angular out-of-memory heap-memory angular2-aot

我正在开发一个angular2项目。我在命令下运行以构建AOT软件包。

  

ng build --aot --prod

但它返回错误:

 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! bisphone-plus@0.0.0 build: `ng build --aot --prod`
    npm ERR! Exit status 134
    npm ERR!
    npm ERR! Failed at the bisphone-plus@0.0.0 build script.
        npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我搜索了解决方案,并在failed - JavaScript heap out of memory”Angular 2 AOT build error - JavaScript heap out of memory中发现了两个类似的问题。

在这些帖子之后,添加add --max-old-space-size=9000属性,但结果已更改:

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)

该项目不是很大,并且几天前已成功构建。而没有ng build的{​​{1}}有用。

2 个答案:

答案 0 :(得分:0)

这对我有用

node --max_old_space_size=5120 ./node_modules/@angular/cli/bin/ng build --prod --build-optimizer

答案 1 :(得分:0)

通过将2.6.x的类型转换为2.7.x的问题已得到解决。