Error EMFILE too Many Open Files React Native CLI

Try to run a react-native-cli project using react-native start, and the metro bundler fails, saying the following:

events.js 187
throw er; //Unhandled 'error' event

Error: EMFILE: too many open files, watch

Emitted 'error' event on NodeWatcher isntance at:
     at NodeWatcher: checkedEmitError (.../react-native-project/node_modules/sane/src/node_watcher.js:143:12)
     at FSWatcher.emit (events.js:210:5)
     at FSEvent.FSWatcher:_handle onchange (internal/fs/watchers.js:129:12) {
   errno: -24,
   syscall: 'watch',
   code : 'EMFILE',
   filename: null
)
Process terminated. Press <enter> to close the window

Upgrading watchman did not help.

This problem started to happen after having updated Node.js.

Thanks to nvm, I came back to node v8.11.3 and this issue disappeared.

That might help some of you having the same problem…

Just close all other files and try again. If you are running on android make sure to run cd android and ./gradlew clean before react-native run-android. If this doesn’t fix, there might be problem with your file watching service. Try this

$ brew update
$ brew install watchman

 using a Mac and got the EMFile error. It was resolved when I installed the file watcher

brew install watchman

 using a MAC and Node v12.13.1. I upgraded watchman and the issue got resolved.

watchman 4.9.0_2 -> 4.9.0_4

Had this issue after upgrading my node version. Downgrading was not an option in Case.

brew install watchman did not fix the issue, as watchman was already installed on my machine. brew upgrade watchman did the trick for me

Had a bunch of these errors along with others like Could not find “Podfile.lock”, etc. after installing PHP Storm.

Did the following to correct the errors based off a combination of StackOverflow searches:

  1. Download, install, and agree to the XCode license
  2. Install brew via the terminal window at brew.sh
  3. Install node
  4. Followed the instructions in the iOS terminal window in PHPStorm

TLTR: brew install watchman solved it on a Macbook.

New MacBook and was having the same issue with a React Native project. On Windows the project was working perfectly but in Mac, after a few seconds of running the project with npm start, it crashed with this error:

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:178:28)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ start: `expo start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

PS: npm install didn’t work. It has to be with brew install.

For those who use older MacOS version: my MacOS version was 10.12 Sierra, even I followed the steps to update brew, install watchman, I still got the issue. But after I upgraded to 10.15 Catalina, and follow the steps again, it works.

For me, a simple upgrade watchman didn’t help, and neither did changing my Node version.

Building on an M1 Mac using XCode 12.5 and had to:

  • Install watchman on using an x86_64 instance of homebrew
  • Run the metro server in a Rosetta terminal
  • Run XCode without Rosetta

If this is the first time you’re installing a package using the x86_64 instance of homebrew remember to add it to your PATH.

Leave a Reply