ESLint Out of Memory Error

08-18-2021

When using ESLint with a lot of files or plugins, it’s possible to cause an out of memory error. This can be frustrating and difficult to debug. Depending on the number and size of your files and the various plugins you have configured this error is very likely. Here are some tips for debugging and resolving.

First we need to get an idea of what is happening. By enabling the DEBUG flag before running the ESLint command(s) we can get an idea of how much memory is being used throughout the process. This can be a wildcard, DEBUG=*, or a more targeted debug statement, DEBUG=typescript-eslint

1
2
3
4
5
DEBUG=*

# OR

DEBUG=typescript-eslint

This will provide a significant amount of information about the time certain tasks take to execute and what files might be an issue.

Additionally we can increase the default memory that Node will allocate to the ESLint process by increasing the --max-old-space-size value, provided your system has the available resources.

1
2
3
4
5
6
export NODE_OPTIONS="--max-old-space-size=4096"
DEBUG=* eslint --config <config file> <folders/files>

# OR

NODE_OPTIONS=--max-old-space-size=4096 DEBUG=* eslint --config <config file> <folders/files>

Additionally ESLint provides an environment variable to measure the length of time it takes for certain rules to execute. The TIMING=1 flag can be passed in before calling ESLint.

1
TIMING=1 eslint --config .eslintrc.js <folders/ files>

These are some of the easy to use tools available to start troubleshooting ESLint performance issues.