I'm working on a quite huge react application and have recently encountered the following problem:
When I start my app with npm start it works just fine and nothing seems wrong, even though I get
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
From time to time in my console output, which doesn't really prevent my app from running. However, when I try to actually build my app, the very same error appears and build folder doesn't contain all the files. I've tried increasing --max-old-space-size up to 32GB, though it didn't really help.
Full output:
<--- Last few GCs --->
[360:000001C14A7A3D80] 58555 ms: Mark-sweep (reduce) 1993.9 (2033.6) -> 1993.9 (2033.1) MB, 615.8 / 0.0 ms (average mu = 0.685, current mu = 0.000) last resort GC in old space requested
[360:000001C14A7A3D80] 59180 ms: Mark-sweep (reduce) 1993.9 (2005.1) -> 1993.7 (2005.1) MB, 625.3 / 0.0 ms (average mu = 0.510, current mu = 0.000) last resort GC in old space requested
<--- JS stacktrace --->
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: 00007FF7F282052F napi_wrap+109311
2: 00007FF7F27C5256 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfElementsOffset+33302
3: 00007FF7F27C6026 node::OnFatalError+294
4: 00007FF7F309163E v8::Isolate::ReportExternalAllocationLimitReached+94
5: 00007FF7F30764BD v8::SharedArrayBuffer::Externalize+781
6: 00007FF7F2F2094C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516
7: 00007FF7F2F1BD61 v8::internal::Heap::AllocateExternalBackingStore+1569
8: 00007FF7F2F35F06 v8::internal::Factory::AllocateRaw+166
9: 00007FF7F2F49924 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller+84
10: 00007FF7F2F49C23 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithMap+35
11: 00007FF7F2D50D6C v8::internal::OrderedHashTable<v8::internal::OrderedHashMap,2>::Allocate+124
12: 00007FF7F2D5356B v8::internal::OrderedHashTable<v8::internal::OrderedHashMap,2>::Rehash+59
13: 00007FF7F2D5234A v8::internal::OrderedHashTable<v8::internal::OrderedHashMap,2>::EnsureGrowable+90
14: 00007FF7F2C89837 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+122119
15: 00007FF7F3119FED v8::internal::SetupIsolateDelegate::SetupHeap+463949
Moreover, it happens in few environments. Both on my local machine and when I try to build it through Gitlab CI/CD