FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed — JavaScript heap out of memory
1 min readMar 17, 2023
This error message is commonly encountered when running a Node.js application or a script that uses the V8 engine (which powers JavaScript) on a system with insufficient memory.
The message indicates that the V8 engine has run out of memory (JavaScript heap), and it is unable to allocate more memory to the application or script.
To resolve this issue, you can try the following steps:
- Increase the heap memory limit: You can increase the heap memory limit of Node.js by setting the — max-old-space-size flag to a higher value when running the script or application. For example, you can set it to 4096 MB by running:
node --max-old-space-size=4096
node --max-old-space-size=12288
ornode --max-old-space-size=16384
,- Optimize your code: If your code is allocating a lot of memory, you can try to optimize it to use less memory. You can use tools such as the Node.js memory profiler to identify memory leaks and optimize your code.
- Use a stream-based approach: If you are processing large files or data streams, you can consider using a stream-based approach to process the data in smaller chunks, rather than loading the entire data set into memory.
- Upgrade your system’s memory: If none of the above solutions work, you can consider upgrading your system’s memory to provide more memory to the application or script.