shinke1987.net
雑多な備忘録等のはず。
他のカテゴリ・タブ
目次
PR

npm run build時のheap out of memoryエラーへの対応ログ

2025-08-19 2025-08-19
カテゴリ: React

発端

npm run buildコマンドを実行すると、

スワップ領域が約2GBあり、ほぼ使われていなかったので問題無さそうだけど下記エラーが表示された。

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

 1: 0xe36196 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node]
 2: 0x123f4a0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
 3: 0x123f777 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
 4: 0x146d1a5  [node]
 5: 0x1486a19 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 6: 0x145b0e8 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 7: 0x145c015 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 8: 0x1434cee v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
 9: 0x18962ec v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
10: 0x1df2476  [node]
中止 (コアダンプ)

下記コマンドでNode.jsのヒープメモリ制限を確認すると、結果は396MBだった。

node -e 'console.log(Math.floor(v8.getHeapStatistics().heap_size_limit/1024/1024))'

解決

下記コマンドを実行し、一時的にメモリを約1GB(スワップ領域の半分)使うよう設定したら、無事ビルドできた。

NODE_OPTIONS="--max-old-space-size=1024" npm run build
同一カテゴリの記事