ENOMEM node system_error ai_generated partial

Error: ENOMEM: not enough memory

ID: node/enomem

Also available as: JSON · Markdown
75%Fix Rate
85%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active

Root Cause

System out of memory. Node process or system-wide memory exhaustion.

generic

Workarounds

  1. 90% success Profile memory usage to find leaks: node --inspect + Chrome DevTools
    node --inspect + Chrome DevTools

    Sources: https://nodejs.org/en/learn/diagnostics/memory/using-heap-snapshot

  2. 88% success Process data in streams instead of loading everything into memory
    const { createReadStream } = require('fs');
    const stream = createReadStream('large-file.json');
    stream.on('data', chunk => processChunk(chunk));

    Sources: https://nodejs.org/api/stream.html

  3. 85% success Check for common leaks: growing arrays, unclosed connections, event listener accumulation
    growing arrays, unclosed connections, event listener accumulation

    Sources: https://nodejs.org/en/learn/diagnostics/memory

Dead Ends

Common approaches that don't work:

  1. Increase --max-old-space-size to very large value 70% fail

    If system RAM is exhausted, increasing V8 heap won't help

  2. Add swap space 60% fail

    Swap is extremely slow — fix the memory usage instead

Error Chain

Frequently confused with: