ANGULAR 使用 ng build --prod 编译报内存错误的解决办法

如果你遇到如下的情况

<--- Last few GCs --->

[13724:0000020D39C660D0] 231298 ms: Mark-sweep 1356.3 (1433.6) -> 1356.3 (1433.6) MB, 1194.3 / 0.0 ms allocation failure GC in old space requested [13724:0000020D39C660D0] 232615 ms: Mark-sweep 1356.3 (1433.6) -> 1356.3 (1426.6) MB, 1198.3 / 0.0 ms last resort GC in old space requested [13724:0000020D39C660D0] 233976 ms: Mark-sweep 1356.3 (1426.6) -> 1356.3 (1426.6) MB, 1361.9 / 0.0 ms last resort GC in old space requested
==== JS stack trace =========================================

Security context: 000003D3AF3A5879 
    1: forEachTrailingCommentToEmit(aka forEachTrailingCommentToEmit) 
[D:\workspace\test5\node_modules\@angular-devkit\build-      optimizer\node_modules\typescript\lib\typescript.js:~68706]      [pc=0000011FBA279296](this=000002F7A0B022D1 <un
defined>,end=146101,cb=000002223F807211 <JSFunction 
emitTrailingCommentOfPosition (sfi = 0000026706B3E149)>)
    2: emitTrailingCommentsOfPosition(aka emitTrailingC...


FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of 
memory
 1: node_module_register
 2: v8::internal::FatalProcessOutOfMemory
 3: v8::internal::FatalProcessOutOfMemory
 4: v8::internal::Factory::NewCodeRaw
 5: v8::internal::Factory::NewCode
 6: v8::internal::modulo
 7: v8::internal::compiler::ControlFlowOptimizer::TryBuildSwitch
 8: v8::internal::ZoneVector 
__ptr64>::ZoneVector
9: v8::internal::compiler::Pipeline::AllocateRegistersForTesting
10: v8::internal::compiler::ValueNumberingReducer::operator=
11: v8::internal::CompilationJob::FinalizeJob
12: v8::internal::compiler::InstructionSelector::isolate
13: v8::internal::Compiler::FinalizeCompilationJob
14: v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions
15: v8::internal::StackGuard::HandleInterrupts
16: v8::internal::wasm::WasmOpcodes::TrapReasonMessage
17: 0000011FB84843C1

嗯,可以这么解决:

在package.json文件中做如下配置:

  "build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod"

然后打包的时候 :

npm run build-prod

 

转载于:https://www.cnblogs.com/timetimetime/p/9120137.html

你可能感兴趣的:(ANGULAR 使用 ng build --prod 编译报内存错误的解决办法)