FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
TL;DRThis error occurs when a JavaScript program, typically running in Node.js, tries to use more memory than the default limit allows and the system cannot allocate any more.
Most likely cause: The app needs more memory than Node.js allows by default
Try first: Check for obvious memory leaks in the code
Likely causes
- The app needs more memory than Node.js allows by defaultmost likely
- A memory leak in the JavaScript code is using up memory over timepossible
- The computer itself has very little available RAMless likely
How to fix it
Safest first: SafeChanges settingsDangerous
Check for obvious memory leaks in the codeSafe
Look for large arrays, objects, or loops that keep growing without being cleared, especially in long-running scripts or servers.
Try running the script with a larger memory limitChanges settings
Add the --max-old-space-size flag when starting Node.js to give it more heap space. Replace 4096 with a higher number if needed and use your actual script name.
node --max-old-space-size=4096 yourscript.js
If that didn't fix it
Run the script with the Node.js inspector flag and capture a heap snapshot to inspect memory usage.
When to see a technician
If this happens on a production server or you cannot identify the memory-heavy part of the code, ask an experienced developer to review it.
Quick answers
- What does FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory mean?
- This error occurs when a JavaScript program, typically running in Node.js, tries to use more memory than the default limit allows and the system cannot allocate any more.
- What causes FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory?
- The app needs more memory than Node.js allows by default. (most likely) A memory leak in the JavaScript code is using up memory over time. (possible) The computer itself has very little available RAM. (less likely)
- How do I fix FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory?
- Try these in order, safest first: 1. Check for obvious memory leaks in the code. 2. Try running the script with a larger memory limit.
- What if that didn't fix it?
- Run the script with the Node.js inspector flag and capture a heap snapshot to inspect memory usage.
- When should I see a technician?
- If this happens on a production server or you cannot identify the memory-heavy part of the code, ask an experienced developer to review it.
Related errors
codeFATAL: password authentication failed for user "postgres"codefatal: Authentication failed for 'https://github.com/user/repo.git/'codeTypeError: Failed to fetchcodeError: Hydration failed because the initial UI does not match what was rendered on the servercodeIndexError: list index out of rangecodedocker: Error response from daemon: Bind for [IP]:8080 failed: port is already allocated