ng serve –build で GC エラー
ng serve –build した時に、下記のエラーで失敗した。GC でメモリ不足になった様子。
<--- Last few GCs ---> [1060:0x103008200] 183715 ms: Mark-sweep 1338.0 (1464.4) -> 1338.0 (1464.4) MB, 801.2 / 0.0 ms allocation failure GC in old space requested [1060:0x103008200] 184781 ms: Mark-sweep 1338.0 (1464.4) -> 1338.0 (1431.4) MB, 1065.2 / 0.0 ms last resort GC in old space requested [1060:0x103008200] 185706 ms: Mark-sweep 1338.0 (1431.4) -> 1338.0 (1431.4) MB, 924.3 / 0.0 ms last resort GC in old space requested <--- JS stacktrace ---> ==== JS stack trace ========================================= Security context: 0x142ac16257c1 1: /* anonymous */ [.../node_modules/source-map/lib/source-node.js:~342] [pc=0x34f4169095f4](this=0x142a5bd8c211 ,chunk=0x142a31a037c1 ,original=0x142ac6552a71 2: SourceNode_walk [.../node_modules/source-map/lib/source-node.js:~221] [pc=0x34f41694b65e](this=0x142adcc1a60… FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node::Abort() [.../.nodebrew/current/bin/node] 2: node::FatalException(v8::Isolate, v8::Local, v8::Local) [.../.nodebrew/current/bin/node] 3: v8::internal::V8::FatalProcessOutOfMemory(char const, bool) [.../.nodebrew/current/bin/node] 4: v8::internal::Factory::NewUninitializedFixedArray(int) [.../.nodebrew/current/bin/node] 5: v8::internal::(anonymous namespace)::ElementsAccessorBase >::GrowCapacity(v8::internal::Handle, unsigned int) [.../.nodebrew/current/bin/node] 6: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object*, v8::internal::Isolate) [.../.nodebrew/current/bin/node] 7: 0x34f4154042fd 8: 0x34f4169095f4 Abort trap: 6
OS 再起動してもダメ。メモリ割り当てを増やす必要あり?どこで?
下記に対処法があった。
https://www.angulartutorial.net/2020/02/how-to-solve-javascript-heap-out-of.html
デフォルトはヒープが1.4GBっぽいので、2GBぐらいでまずは試す。
ng node --max_old_space_size=2048 && ng serve --prod
あれ?ng node なんてないというエラー…。なんか怪しい気がしたんだよな。
結局、package.json の scripts を修正してうまくいった。
"start:prod": "node --max_old_space_size=2048 ./node_modules/@angular/cli/bin/ng serve --prod",
で、下記を実行。
npm run start:prod
このページを参考にした。
https://github.com/angular/angular-cli/issues/1652
コメントを残す