Allocate heap memory to JavaScript in Next.js, Reactjs – Code Example


You may allocate heap memory to JavaScript in any node framework like NextJs or ReactJs from package.json. Generally you never encounter heap error but if you are getting one then most probably there is some issue in your code like infinite loops, circular dependency etc. You will get this error – FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory.

Solution with Code Example

Open package.json, change this line –

"dev": "next",

with this one –

"dev": "NODE_OPTIONS=--max-old-space-size=4096 next",

This will add 4096 MB of memory to this application.