Node.js
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
JavaScript Heap Out of Memory
Node.js ran out of memory while allocating space for JavaScript objects. The default heap limit is around 1.5–2 GB depending on the platform.
Common Causes
- Processing very large datasets in memory
- Memory leaks (unclosed connections, growing caches)
- Recursive functions with deep call stacks
- Loading huge JSON/files without streaming
Fixes
- 1. Increase heap size temporarily
NODE_OPTIONS=--max-old-space-size=4096 node your-app.js
- 2. Use streaming for large files
const stream = fs.createReadStream('large.json'); stream.pipe(JSONStream.parse()); - 3. Process data in chunks
for (const chunk of chunks) { processChunk(chunk); global.gc?.(); // if --expose-gc } - 4. Profile with --inspect
node --inspect --max-old-space-size=4096 app.js
Still not fixed?
- • Search the exact error message on Stack Overflow or GitHub Issues
- • Check the official docs for the language or tool
- • Ensure your versions (Node, Python, npm, Docker) are up to date
- • Try in a minimal reproduction (new project, single file)
Related Errors
DuskTools That Might Help
All Errors
ModuleNotFoundErrorAddress Already in UseIndentationErrorCannot Find ModulePeer Dependency WarningCORS Policy BlockedTypeError: 'NoneType' Not SubscriptableMerge ConflictDocker Port Already AllocatedENOENT: No Such File or DirectoryKeyErrorMaxListenersExceededWarningRecursionErrorDetached HEAD StateEACCES: Permission DeniedValueErrorNo Space Left on DeviceERR_REQUIRE_ESMFileNotFoundError