Skip to content

Instantly share code, notes, and snippets.

@sergiks
Last active September 12, 2024 18:05
Show Gist options
  • Save sergiks/1b55ee0d1d8accd76bb771618f48ede4 to your computer and use it in GitHub Desktop.
Save sergiks/1b55ee0d1d8accd76bb771618f48ede4 to your computer and use it in GitHub Desktop.
Find NodeJS V8 heap size limit from command line

Error message

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

JS heap memory

V8 exposes method v8.getHeapStatistics() that returns an object. Field heap_size_limit contains the number of Bytes.

This value can be increased by setting --max-old-space-size option (in Mb). In example, to 8 Gb:

export NODE_OPTIONS='--max-old-space-size=8192'
npm run build

or

node --max-old-space-size=8192 index.js

However this might not help if the system has very little memory.

System memory

Check available memory by running free -m command in Linux / MacOS shell. Low available memory can be increased by enabling swap.

node -e 'const { getHeapStatistics } = require("node:v8"); console.log(getHeapStatistics().heap_size_limit);'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment