FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

I’m trying to deploy my app but I’m getting this error:
7:13:48 PM: Creating an optimized production build…
7:19:46 PM: <— Last few GCs —>
7:19:46 PM: [1601:0x34475b0] 268332 ms: Mark-sweep 1310.1 (1473.5) -> 1310.0 (1474.0) MB, 2566.1 / 0.0 ms allocation failure GC in old space requested
7:19:46 PM: [1601:0x34475b0] 270627 ms: Mark-sweep 1310.0 (1474.0) -> 1310.0 (1439.5) MB, 2295.2 / 0.0 ms last resort GC in old space requested
7:19:46 PM: [1601:0x34475b0] 272972 ms: Mark-sweep 1310.0 (1439.5) -> 1310.0 (1438.5) MB, 2343.7 / 0.0 ms last resort GC in old space requested
7:19:46 PM: <— JS stacktrace —>
7:19:46 PM: ==== JS stack trace =========================================
7:19:46 PM: Security context: 0x25b78a425891
7:19:46 PM: 1: SourceMapGenerator_addMapping [/opt/build/repo/node_modules/source-map/lib/source-map-generator.js:~103] [pc=0x62502af81ca](this=0xe582536ad9 ,aArgs=0x1971587a9bd1 )
7:19:46 PM: 2: /* anonymous /(aka / anonymous /) [/opt/build/repo/node_modules/terser/dist/bundle.min.js:~1] [pc=0x62502acc8a6](this=0x3887c40822d1 ,t=…
7:19:46 PM: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
7:19:46 PM: 1:
7:19:46 PM: node::Abort() [/opt/buildhome/.nvm/versions/node/v8.16.0/bin/node]
7:19:46 PM: 2:
7:19:46 PM: 0x8cd14c [/opt/buildhome/.nvm/versions/node/v8.16.0/bin/node]
7:19:46 PM: 3:
7:19:46 PM: v8::Utils::ReportOOMFailure(char const
, bool) [/opt/buildhome/.nvm/versions/node/v8.16.0/bin/node]
7:19:46 PM: 4:
7:19:46 PM: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/opt/buildhome/.nvm/versions/node/v8.16.0/bin/node]
7:19:46 PM: 5:
7:19:46 PM: v8::internal::factory::NewUninitializedFixedArray(int) [/opt/buildhome/.nvm/versions/node/v8.16.0/bin/node]
7:19:46 PM: 6:
7:19:46 PM: 0xd83553 [/opt/buildhome/.nvm/versions/node/v8.16.0/bin/node]
7:19:46 PM: 7:
7:19:46 PM: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [/opt/buildhome/.nvm/versions/node/v8.16.0/bin/node]
7:19:46 PM: 8: 0x625021842fd

1 Like

I have a similar problem, building a Gatsby site and getting error:

2:28:35 PM: <--- Last few GCs --->
2:28:35 PM: [1541:0x3bb00a0]   154094 ms: Mark-sweep 1351.5 (1425.5) -> 1350.8 (1428.0) MB, 3449.9 / 0.0 ms  (average mu = 0.076, current mu = 0.007) allocation failure scavenge might not succeed
2:28:35 PM: <--- JS stacktrace --->
2:28:35 PM: ==== JS stack trace =========================================
2:28:35 PM:     0: ExitFrame [pc: 0x114d680dbe1d]
2:28:35 PM: Security context: 0x369735b1e6e9 <JSObject>
2:28:35 PM:     1: addMappingWithCode [0x2a57bba6f771] [/opt/build/repo/node_modules/webpack-sources/node_modules/source-map/lib/source-node.js:~150] [pc=0x114d692be575](this=0x078de248d481 <JSGlobal Object>,mapping=0x3605ff1e57b9 <Object map = 0x314af4c97809>,code=0x2a12adc6a431 <String[9]: 9633]}}},>)
2:28:35 PM:     2: /* anonymous */ [0x3d024199afc9] [/opt/build/repo/node_modul...
2:28:35 PM: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
2:28:35 PM:  1: 0x8f9d10 node::Abort() [node]
2:28:35 PM:  2: 0x8f9d5c  [node]
2:28:35 PM:  3: 0xaffd0e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
2:28:35 PM:  4: 0xafff44 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
2:28:35 PM:  5: 0xef4152  [node]
2:28:35 PM:  6: 0xef4258 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [node]
2:28:35 PM:  7: 0xf00332 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
2:28:35 PM:  8: 0xf00c64 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
2:28:35 PM:  9: 0xf038d1 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
2:28:35 PM: 10: 0xeccd54 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node]
2:28:35 PM: 11: 0x116cede v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
2:28:35 PM: 12: 0x114d680dbe1d
2:28:42 PM: /usr/local/bin/build: line 34:  1541 Aborted                 (core dumped) gatsby build

These are effectively saying “Your build ran out of memory”. Node doesn’t handle that super well, in terms of “ok let me try scaling back” but instead just charges forward and eventually your build fails.

You’ll need to reduce memory usage. You need to aim for approximately 3Gb maximum for reliable builds. You’ll sometimes have more (depending on the number of other builds running simultaneously, which you have no control over or visibility into), but that’s the amount you can rely on and into which your build should fit on our Starter and Pro teams.

Enterprise teams have available custom build resources, where runtime, CPU, and memory available are adjustable.

In the case of gatsby @szokrika, it is likely that you use a poorly behaved plugin such as the ones mentioned in #5 in this article: https://www.netlify.com/blog/2018/06/28/5-pro-tips-and-plugins-for-optimizing-your-gatsby---netlify-site/ , so the fix for you may be as easy as finding the offending module and choosing not to use it.

Without more details such as a link to your build logs, @BrunoQuaresma, I couldn’t give you any similarly specific information since I don’t know what you’re using to build.

@BrunoQuaresma and @szokrika, this could be the following issue:

I fixed using env variables:
NODE_OPTIONS=–max_old_space_size=4096

1 Like