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

React NativeReact Native-Ios

React Native Problem Overview


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

React Native Solutions


Solution 1 - React Native

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 - React Native

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

brew install watchman

Solution 3 - React Native

In my case, 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 (I updated to v12.0.4) and this issue disappeared.

That might help some of you having the same problem...

Solution 4 - React Native

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 5 - React Native

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 - React Native

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

Delete node_modules folder and run npm install solved the issue.

Solution 7 - React Native

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 8 - React Native

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 9 - React Native

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 10 - React Native

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 11 - React Native

Try "brew install watchman" command,

if "brew" not install then follow below steps

Follow this steps, This is worked for me.

Solution 12 - React Native

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 - React Native

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 - React Native

The following steps worked for me on MacOS:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmirView Question on Stackoverflow
Solution 1 - React NativeRomit KumarView Answer on Stackoverflow
Solution 2 - React NativeKaushikView Answer on Stackoverflow
Solution 3 - React NativeŻabojadView Answer on Stackoverflow
Solution 4 - React NativeAshish VyasView Answer on Stackoverflow
Solution 5 - React NativeMike HamiltonView Answer on Stackoverflow
Solution 6 - React NativelukeView Answer on Stackoverflow
Solution 7 - React NativeLorenzo CastilloView Answer on Stackoverflow
Solution 8 - React NativeOscarView Answer on Stackoverflow
Solution 9 - React NativeRedsebView Answer on Stackoverflow
Solution 10 - React NativeFontFamilyView Answer on Stackoverflow
Solution 11 - React NativeVishal GadhiyaView Answer on Stackoverflow
Solution 12 - React NativeMr. RobotView Answer on Stackoverflow
Solution 13 - React NativeMichaView Answer on Stackoverflow
Solution 14 - React NativeJalome ChirwaView Answer on Stackoverflow