React-native: “Error watching file for changes: EMFILE” when run the examples from facebook/react-native/Examples

Created on 24 Sep 2016  ·  18Comments  ·  Source: facebook/react-native

I want to run the Examples from facebook/react-native/Examples in OS X 10.12.

First I use npm install and then use npm start:

There is an error:

Error watching file for changes: EMFILE
{"code":"EMFILE","errno":"EMFILE","syscall":"Error watching file for changes:","filename":null}
Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1008:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1406:11)

Then I use Xcode run the code but there is the same error.
Need help or advice. Thanks very much.

p.s. When I init a new project and then use react-native run-ios or Xcode , and there is the same error

Locked

Most helpful comment

@SupriyaKalghatgi This may help. It appears to have helped other people already.

https://gist.github.com/brennanMKE/f6aa55b452ecda2f4c7a379e21647c88

React Native Trouble

Updating to macOS Sierra is causing trouble with React Native due to some of the Node.js and system utilities it uses. Specifically the watch utility fails due to a limit on the number of files which can be opened at a time.

The following command shows the current limit.

launchctl limit maxfiles

It may show 256 as the lower limit. The following command will change the limits.

sudo launchctl limit maxfiles 2048 unlimited

Next you also want to uninstall react-native and reinstall it so you get a version which works better with Sierra. You also want to update Homebrew and install the current version of watchman.

npm uninstall -g react-native-cli
npm install -g react-native-cli
brew update
brew install watchman

Now try building and running your React Native project on macOS Sierra.

All 18 comments

Fwiw, I was running into the same issue, and this solved it: https://github.com/facebook/react-native/issues/910

Yeah, it was already solved

i use this command to resolve my problem
sudo react-native start

You really do not want to use sudo regularly, especially with software which is under development. It gives that process unrestricted access to your computer and files which opens you up to major security risks. With all of the npm modules in your Node.js you cannot know that one of them does not contain a bug which could accidentally damage files on your computer or even do this maliciously.

What you want to do is increase the maximum allowed number of file descriptors. This command will show you the current maximum.

ulimit -n

Adding a number will set the maximum to the new value. This will allow you to run the react-native command without sudo.

ulimit -n 2560

If you have homebrew earlier and you have upgrade to Sierra, then it can solve your problem. Run this in your terminal, then again run react-native build.

sudo chown -R $(whoami) /usr/local

If anyone else comes across this, installing watchman through brew ended up fixing things for me.

None of the mentioned solutions helped me

@SupriyaKalghatgi This may help. It appears to have helped other people already.

https://gist.github.com/brennanMKE/f6aa55b452ecda2f4c7a379e21647c88

React Native Trouble

Updating to macOS Sierra is causing trouble with React Native due to some of the Node.js and system utilities it uses. Specifically the watch utility fails due to a limit on the number of files which can be opened at a time.

The following command shows the current limit.

launchctl limit maxfiles

It may show 256 as the lower limit. The following command will change the limits.

sudo launchctl limit maxfiles 2048 unlimited

Next you also want to uninstall react-native and reinstall it so you get a version which works better with Sierra. You also want to update Homebrew and install the current version of watchman.

npm uninstall -g react-native-cli
npm install -g react-native-cli
brew update
brew install watchman

Now try building and running your React Native project on macOS Sierra.

Re-installing the node_modules folder worked for me. Just a thought lol.

Reinstalling node modules worked for me too. But its a pain to do this every time.

@brennanMKE You saved me like a hero! :) Thanks much!

For me, it turned out that I had npm link-ed something else (the Sails socket client in my case), which seems to have thrown things into a tizzy. Removing the linked dep and rerunning react-native-cli seemed to fix things up

I didn't have watchman installed. I switch between computers and thought both had it installed but I was wrong. 😞

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:

  1. Clear watchman watches: watchman watch-del-all.
  2. Delete the node_modules folder: rm -rf node_modules && npm install.
  3. Reset packager cache: rm -fr $TMPDIR/react-* or npm start -- --reset-cache.

If all the above does not work - find out if you have a permission problem with brew postinstall watchman.
error will be Error: Permission denied - /usr/local/var/run/watchman
If that is the case change the permission on the watchman directory before you try reinstalling with brew postinstall watchman
change permission with sudo chown -R "$USER":admin /usr/local/var/run

This sort of thing happens enough with RN that I just put an entry in my package.json:

"clean-start": "watchman watch-del-all && rm -rf node_modules && yarn install && rm -rf $TMPDIR/react* && npm start --reset-cache"

Running that fixed whatever problem I was having with this EMFILE thing.

I didn't have watchman installed. Simply installing via brew install watchman fixed this issue, I didn't have to make any other changes. (I'm on OS X.)

If you are like me, I did everything suggested but kept ignoring brew and used npm to install watchman. Using brew fixed it for me.

Was this page helpful?
0 / 5 - 0 ratings