关于大型angular项目编译问题

背景

当angular项目比较庞大的时候,打包时间就会比较慢。然后这个时候会出现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<--- Last few GCs --->

[22517:0x102802400] 176590 ms: Mark-sweep 1367.9 (1430.1) -> 1367.9 (1430.1) MB, 1351.8 / 0.0 ms allocation failure GC in old space requested
[22517:0x102802400] 178544 ms: Mark-sweep 1367.9 (1430.1) -> 1367.9 (1427.1) MB, 1771.4 / 0.0 ms last resort GC in old space requested
[22517:0x102802400] 180071 ms: Mark-sweep 1367.9 (1427.1) -> 1367.9 (1427.1) MB, 1526.6 / 0.0 ms last resort GC in old space requested


<--- JS stacktrace --->

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

Security context: 0x2f04b2e25529 <JSObject>
1: forEachChild [/Users/stone-jin/Downloads/metronic_v5.2 3/metronic_v5.2/angular/dist/demo/default/node_modules/typescript/lib/typescript.js:~11931] [pc=0x305175bbd919](this=0x2f04ace04a51 <Object map = 0x2f04b1451ae9>,node=0x2f04692c72a1 <NodeObject map = 0x2f04352d8e11>,cbNode=0x2f0421f75a69 <JSFunction visitNode (sfi = 0x2f0414f144b9)>,cbNodes=0x2f04fc6822d1 <undefined>)
2: arguments...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/lib/node_modules/node/bin//node]
2: node::FatalTryCatch::~FatalTryCatch() [/usr/local/lib/node_modules/node/bin//node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/lib/node_modules/node/bin//node]
4: v8::internal::Factory::NewCodeRaw(int, bool) [/usr/local/lib/node_modules/node/bin//node]
5: v8::internal::Factory::NewCode(v8::internal::CodeDesc const&, unsigned int, v8::internal::Handle<v8::internal::Object>, bool, int) [/usr/local/lib/node_modules/node/bin//node]
6: v8::internal::CodeGenerator::MakeCodeEpilogue(v8::internal::TurboAssembler*, v8::internal::EhFrameWriter*, v8::internal::CompilationInfo*, v8::internal::Handle<v8::internal::Object>) [/usr/local/lib/node_modules/node/bin//node]
7: v8::internal::compiler::CodeGenerator::FinalizeCode() [/usr/local/lib/node_modules/node/bin//node]
8: v8::internal::compiler::PipelineImpl::FinalizeCode() [/usr/local/lib/node_modules/node/bin//node]
9: v8::internal::compiler::PipelineCompilationJob::FinalizeJobImpl() [/usr/local/lib/node_modules/node/bin//node]
10: v8::internal::Compiler::FinalizeCompilationJob(v8::internal::CompilationJob*) [/usr/local/lib/node_modules/node/bin//node]
11: v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions() [/usr/local/lib/node_modules/node/bin//node]
12: v8::internal::StackGuard::HandleInterrupts() [/usr/local/lib/node_modules/node/bin//node]
13: v8::internal::Runtime_StackGuard(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/lib/node_modules/node/bin//node]
14: 0x305174e042fd
15: 0x305175bbd919

这样的错误信息,不要慌张,这种通用类型的最简单,搜索下就好。

解决办法

大概就是编译慢了,node认为我们有内存泄漏了。所以这个时候我们只要通过- -max-old-space-size=4096 这个来解决我们的问题即可。这个修改在node_modules/.bin下面有个ng文件。然后我们修改这个文件。

在头部的#!/usr/bin/env node之后加上- -max-old-space-size=4096就可以解决我们的问题了。

感谢您的阅读,本文由 大米小米的博客 版权所有。
如若转载,请注明出处:大米小米的博客(http://blog.fedfans.com/page/article/43/
服务器安装maven环境
阿里云服务器配置swap分区