'Error: EMFILE: too many open files - React Native CLI

I 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


Solution 1:[1]

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

Solution 2:[2]

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

brew install watchman

Solution 3:[3]

I'm 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

Solution 4:[4]

For my case, I think this error occurs due to node upgrade.

Delete node_modules folder and run npm install solved the issue.

Solution 5:[5]

I had this issue after upgrading my node version. Downgrading was not an option in my 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.

Solution 6:[6]

TLTR: brew install watchman solved it on a Macbook.

I just got a 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.

Solution 7:[7]

I needed to install watchman with brew as others have done here, however I also needed to update the React Native Xcode build script with this line: export PATH=/opt/homebrew/bin:$PATH so xCode could find watchman in my M1 MacBook Pro.

React Native Xcode build script location: ./node_modules/react-native/scripts/react-native-xcode.sh

Solution 8:[8]

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

I was 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.

Solution 9:[9]

I had a bunch of these errors along with others like Could not find "Podfile.lock", etc. after installing PHP Storm.

I 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

Now working!

Solution 10:[10]

Try "brew install watchman" command,

if "brew" not install then follow below steps

Follow this steps, This is worked for me.

Solution 11:[11]

No matter what I did, I couldn't get this to work. What ended up working for me is using the following command

$ sudo sysctl -w kern.maxfiles=10485760
$ sudo sysctl -w kern.maxfilesperproc=1048576

Found at: https://facebook.github.io/watchman/docs/install.html#mac-os-file-descriptor-limits

I have a M1 Pro. Hope this is helpful to someone.

Solution 12:[12]

In my case I got this error after switching dev machines from Linux to OS X. None of the above worked for me until I ran brew upgrade watchman.

Solution 13:[13]

I had watchman installed via macports. However the path to watchman was unknown to to the "Bundle React Native code and images" Build Phase. Adding

export PATH=/opt/local/bin:$PATH

to the beginning of the script fixed the issue for me

Solution 14:[14]

Tried with couple of node versions but giving same error.

brew update watchman

helped to get rid of this error.

Solution 15:[15]

In my case, the icu4c version was wrong. I reinstall icu4c then it's worked. Here is the command which I used:

 brew reinstall icu4c

Solution 16:[16]

Works inside docker: ulimit -n 2048

Solution 17:[17]

The following steps worked for me on MacOS:

  1. Updateing/Installing Homebrew from official site https://brew.sh/
  2. Installing Watchman: brew install watchman

Solution 18:[18]

find_elemenet_by_xpath is depricated that's what you get strike in the app instead you can Use By

from selenium.webdriver.common.by import By
...
driver.find_element(By.XPATH, "").click()