Source Map Generation Out of Memory (2026)

The Error

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
  at SourceMapGenerator.addMapping (node_modules/source-map/lib/source-map-generator.js:107)
  generating source maps for bundle.js (12.4 MB)

This error occurs when building source maps for large bundles exhausts Node’s default 4GB heap. The source map generator holds the entire mapping in memory.

The Fix

  1. Increase Node’s memory limit for the build:
export NODE_OPTIONS="--max-old-space-size=8192"
npm run build
  1. Or use a lighter source map strategy in webpack:
// webpack.config.js
module.exports = {
  devtool: 'cheap-module-source-map',  // Instead of 'source-map'
};
  1. For Vite, disable source maps in production:
// vite.config.ts
export default {
  build: {
    sourcemap: false,  // Or 'hidden' for error tracking only
  }
};
  1. Rebuild:
NODE_OPTIONS="--max-old-space-size=8192" npm run build

Why This Happens

Full source maps (devtool: 'source-map') generate a complete mapping from every character in the output back to the original source. For large bundles (10MB+), this mapping structure can consume 3-5x the bundle size in memory. Node’s default heap of 4GB is insufficient for bundles that produce source maps exceeding 50MB.

If That Doesn’t Work

  • Split the bundle to reduce per-chunk source map size:
module.exports = {
  optimization: {
    splitChunks: { chunks: 'all', maxSize: 500000 }
  }
};
  • Use nosources-source-map which includes line mappings but not source content:
module.exports = { devtool: 'nosources-source-map' };
  • Upload source maps separately to your error tracking service and exclude them from the bundle.

Prevention

Add this to your CLAUDE.md:

# Source Maps
- Use cheap-module-source-map for development, hidden-source-map for production.
- Set NODE_OPTIONS=--max-old-space-size=8192 in CI build scripts.
- Split bundles to keep chunks under 500KB for manageable source maps.

See Also

This fix also applies if you see variations of this error:

  • Connection or process errors with similar root causes in the same subsystem
  • Timeout variants where the operation starts but does not complete
  • Permission variants where access is denied to the same resource
  • Configuration variants where the same setting is missing or malformed

If your specific error message differs slightly from the one shown above, the fix is likely the same. The key indicator is the operation that failed (shown in the stack trace) rather than the exact wording of the message.

Frequently Asked Questions

Does this error affect all operating systems?

This error can occur on macOS, Linux, and Windows (WSL). The exact error message may differ slightly between platforms, but the root cause and fix are the same. macOS users may see additional Gatekeeper or notarization prompts. Linux users should check that the relevant system packages are installed. Windows users should ensure they are running inside WSL2, not native Windows.

Will this error come back after updating Claude Code?

Updates can occasionally reintroduce this error if the update changes default configurations or dependency requirements. After updating Claude Code, verify your project still builds and runs correctly. If the error returns, reapply the fix and check the changelog for breaking changes.

Can this error cause data loss?

No, this error occurs before or during an operation and does not corrupt existing files. Claude Code’s edit operations are atomic — they either complete fully or not at all. However, if the error occurs during a multi-step operation, you may have partial changes that need to be reviewed with git diff before continuing.

How do I report this error to Anthropic if the fix does not work?

Open an issue at github.com/anthropics/claude-code with: (1) the full error message including stack trace, (2) your Node.js version (node --version), (3) your Claude Code version (claude --version), (4) your operating system and version, and (5) the command or operation that triggered the error.

Try it: Paste your error into our Error Diagnostic for an instant fix.