gulpで「CALL_AND_RETRY_LAST Allocation failed」というエラーが出た時の対処
gulpで「CALL_AND_RETRY_LAST Allocation failed」というエラーが発生
gulp-concatでファイルを結合していたら、以下のようなエラーと遭遇。
<--- Last few GCs ---> 120788 ms: Mark-sweep 1379.7 (1455.9) -> 1379.7 (1455.9) MB, 1211.9 / 0 ms [allocation failure] [GC in old space requested]. 121826 ms: Mark-sweep 1379.7 (1455.9) -> 1379.7 (1455.9) MB, 1038.5 / 0 ms [allocation failure] [GC in old space requested]. 122882 ms: Mark-sweep 1379.7 (1455.9) -> 1379.7 (1455.9) MB, 1055.0 / 0 ms [last resort gc]. 123942 ms: Mark-sweep 1379.7 (1455.9) -> 1379.7 (1455.9) MB, 1060.2 / 0 ms [last resort gc]. <--- JS stacktrace ---> ==== JS stack trace ========================================= Security context: 0x3b31c8a5a91 <JS Object> 1: /* anonymous */(aka /* anonymous */) [0x3b31c8041b9 <undefined>:~2655] [pc=0x2ffd9b29ee8e] (this=0x3b31c8041b9 <undefined>) 2: /* anonymous */(aka /* anonymous */) [0x3b31c8041b9 <undefined>:~2134] [pc=0x2ffd9b2972ac] (this=0x3b31c8041b9 <undefined>) 3: /* anonymous */(aka /* anonymous */) [0x3b31c8041b9 <undefined>:~2599] [pc=0x2ffd9b29b423] (this=0x3b31c8041b9 <undefined>,allow_... FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory zsh: abort gulp build:local
エラーの原因
原因は「out of memory」というエラーの通り、ヒープメモリが不足していたことでした。
参考にさせて頂いたサイトによると、Node.jsは512MBがデフォルトとのこと。
Node.js の out of memory エラー回避方法 : まだプログラマーですが何か?
対処方法
gulpを実行するときに、--max_old_space_size
のオプションを付けてメモリサイズを大きくすればOK。
ただ、手打ちはもちろん、シェルのaliasを設定するのもどうかなと思ったので、
package.jsonに以下のようにスクリプト定義を追加することで対処しました。
"scripts": { "dev": "./node_modules/.bin/gulp --max_old_space_size=8192 dev", }
gulpの場合、オプションの単語がハイフンではなくアンダースコアで繋がれているのが微妙なハマりポイントかも。
- gulp:–max_old_space_size
- node:–max-old-space-size