Fix 'EMFILE: too many open files' error in Jest

When I tried to run jest --watch in a codebase, I received the following error:

Error: EMFILE: too many open files, watch
at FSEvent.FSWatcher._handle.onchange (fs.js:1372:28)
Emitted 'error' event at:
at NodeWatcher.checkedEmitError (/Users/seanmcp/dev/REPO/node_modules/sane/src/node_watcher.js:143:12)
at FSWatcher.emit (events.js:182:13)
at FSEvent.FSWatcher._handle.onchange (fs.js:1378:12)

A Google search of the error message produced three (!) results. The second was a PDF from Mozilla that recommended installing watchman.

Why watchman? #

Watchman is a file-watching service from Facebook that will respond to changes in your files. Jest (also by Facebook) default to using watchman in --watch mode.

Watchman is available on all major platforms. On a Mac or Linux with Homebrew installed, you can run:

brew install watchman

With that installed, Jest’s --watch flag works as expected.

I hope that works for you (and saves you some valuable time)!

Happy testing!

Psalm 127:1 (SDG)

About the author

My name is Sean McPherson, and I am a software engineer interested in all areas of front-end development. Here I write articles about programming for developers of all levels, and occassionally other topics.

Currently I work for and live with my lovely family in Pittsburgh, PA.