Demian
Demian

Reputation: 121

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory | reactjs

I do not have a hard project, I only start it. But when I use npm run dev node js eat more than 4GB of memory and after it, I see the fatal error:

--- Last few GCs --->

[16804:0000018EB02350F0]   128835 ms: Mark-sweep (reduce) 4092.4 (4101.2) -> 4091.5 (4102.4) MB, 2886.3 / 0.0 ms  (average mu = 0.106, current mu = 0.002) allocation failure scavenge might not succeed
[16804:0000018EB02350F0]   133745 ms: Mark-sweep (reduce) 4092.7 (4104.7) -> 4091.8 (4104.9) MB, 4899.7 / 0.0 ms  (average mu = 0.042, current mu = 0.002) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF7D7A94BDF napi_wrap+111007
 2: 00007FF7D7A38166 v8::base::CPU::has_sse+59910
 3: 00007FF7D7A39066 node::OnFatalError+294
 4: 00007FF7D831217E v8::Isolate::ReportExternalAllocationLimitReached+94
 5: 00007FF7D82F6F4D v8::SharedArrayBuffer::Externalize+781
 6: 00007FF7D81A008C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516
 7: 00007FF7D81AB4AA v8::internal::Heap::ProtectUnprotectedMemoryChunks+1258
 8: 00007FF7D81A85E9 v8::internal::Heap::PageFlagsAreConsistent+2457
 9: 00007FF7D819D181 v8::internal::Heap::CollectGarbage+2049
10: 00007FF7D819B385 v8::internal::Heap::AllocateExternalBackingStore+1349
11: 00007FF7D81BB7FB v8::internal::Factory::NewFillerObject+203
12: 00007FF7D7EEA2D1 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+1409
13: 00007FF7D839B03D v8::internal::SetupIsolateDelegate::SetupHeap+465325
14: 0000019D8C81DCE3
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! [email protected] dev: `next dev`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I use the pretty default package.json:

"scripts": {
    "dev": "next dev",
    "debug": "set NODE_OPTIONS=--inspect && next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "stylelint": "stylelint \"**/*.css\" --fix"
},

If you need sth else I would add this

Upvotes: 2

Views: 5162

Answers (1)

Balastrong
Balastrong

Reputation: 4474

You need to give node more memory.

A quick workaround can be manually increasing max_old_space_size in your console. From that moment, all builds will go fine. You can launch this command:

SET NODE_OPTIONS=--max_old_space_size=8048

If you want a more stable solution, you should change the definition of your dev command with something like:

SET NODE_OPTIONS=--max_old_space_size=8048 && next dev

So that you make sure the max_old_space_size is always set to a higher number than default without doing anything different than before.

8048 is the size in bytes, so 8GB and you can put whatever number you want. If you put more than your RAM, it will go with pagination so it can be a bit slower.

Seamless :)

Upvotes: 2

Related Questions