create-react-native-app: Start script hangs without error when there are no available inotify watches

Description

I tried to run npm start in a new project (i.e. I ran the four commands under “Quick Overview”), and it hanged indefinitely (well, at least for several minutes until I aborted) after the output “Starting packager…”.

Running react-native start gave the error ERROR watch {path} ENOSPC, which made me realize that there were no available inotify watches.

After increasing fs.inotify.max_user_watches, npm start started and ran normally.

Expected Behavior

npm start should give a warning or exit with an error saying that there are no available watches, so it can’t start.

Observed Behavior

npm start hanged with this output, and never continued:

$ npm start

> my-app@0.1.0 start /home/trygve/dev/create-react-native-app/my-app
> react-native-scripts start

13.49.26: Starting packager...

Environment

Please run these commands in the project folder and fill in their results:

  • npm ls react-native-scripts: react-native-scripts@0.0.30
  • npm ls react-native: react-native@0.44.2
  • npm ls expo: expo@17.0.0
  • node -v: v7.10.0
  • npm -v: 4.6.1
  • yarn --version: 0.24.6
  • watchman version: Not installed

Also specify:

  1. Operating system: Arch Linux
  2. Phone/emulator/simulator & version: Not relevant

Reproducible Demo

Ran npm start in a clean project just created, so nothing to provide here.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 44
  • Comments: 59 (11 by maintainers)

Most upvoted comments

I also have the same issue, using OSX Sierra 10.12.5. sysctl returns sysctl: unknown oid 'fs.inotify.max_user_watches'. Any ideas? 😦 I can’t start up any react iOS app, the simulator does, but nothing else happens and it gets stuck in the Packager thing…

Nevemind, fixed it with this:

sudo sysctl -w kern.maxfiles=524288
sudo sysctl -w kern.maxfilesperproc=524288

@tetralix On Linux do “sudo sysctl -w fs.inotify.max_user_watches=10000”. This changes kernel sysctl value. This is temporary until reboot. To make it permanent, add fs.inotify.max_user_watches=10000 to a file in /etc/sysctl.d directory or /etc/sysctl.conf depending on distro.

@darkguy2008 On my Mac, I had to change the value a little bit, and it worked

  sudo sysctl -w kern.maxfiles=5242880
  sudo sysctl -w kern.maxfilesperproc=524288

Confirming the issue, seen it too and it’s pretty bad bug because it affects newcomers - I’ve created a new empty React native project and it simply hang on “Starting packager…”. Confirming increase of that sysctl fixed the issue.

@nimir : try this in your project root if you haven’t tried yet: ./node_modules/.bin/react-native start

Just ran into this issue. Agreed with the above commenters that something like:

On MacOS run:

    $ brew install watchman

should be added to the error message. Of course adding other relevant information for other OS’s as well. Pretty bad developer experience to have to come to this GH issue & skim to find out what I needed to do just to run the example setup.

FYI, I ran into the same issue again, but fixed with running

sudo sysctl -w kern.maxfiles=5242880
sudo sysctl -w kern.maxfilesperproc=524288

I think it would be weird and confusing to come across this error at very beginning. And it would not hurt to mention this in an obvious position of the document, rather than in this issue.

ADMIN EDIT: these commands work for Mac only.

To solve this issue, just install Watchman via Homebrew (for macOS) with:

$ brew update
$ brew install watchman

Source: Watchman docs. For other operating systems, refer to their docs.

I was getting the same error as @mikeaustin

Unable to start server See https://git.io/v5vcn for more information, either install watchman or run the following snippet: sudo sysctl -w kern.maxfiles=5242880 sudo sysctl -w kern.maxfilesperproc=524288

but once i installed watchman, it worked like a charm!

why does sudo sysctl -w kern.maxfilesperproc=524288 solve this problem? Just curious.

Required 10485760 for me

@brentvatne @dikaiosune We should also add this in Getting Started section. So that it will easier for beginners.

I had the same issue on Ubuntu 16.04.2 LTS. As @s417-lama mentioned #51 contains the solution that worked for me.

But this bug is very frustrating for beginners and should be given priority. @dikaiosune has already taken a note of this. I hope this gets fixed soon.

Spent hours googling, reinstalling, upgrading, downgrading, switching to yarn until I found this issue. Thank you!

+1 to have an error message…

Used this guide to increase the inotify watchers max amount: https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers

Maybe just include a URL to watchman – no sense providing install instructions as they vary by platform and could be subject to change, no sense coupling CRNA to the installation instructions for watchman IMO.

e.g.

6:55:12 p.m.: Unable to start server
For more information:  https://git.io/v5vcn
To resolve, either install watchman:  https://git.io/vxGX7
Or run the following snippet:
  sudo sysctl -w kern.maxfiles=5242880
  sudo sysctl -w kern.maxfilesperproc=524288

OSX; ran into same thing, had to read the entire thread to find out what “install watchman” means and that it doesn’t mean npm, agree with comments that it should at least point to the watchman website, although having it suggest “brew install watchman” would be by far the most helpful.

@sendsent

if (process.platform !== 'win32') {
  var watchmanExists = _crossSpawn2.default.sync('which', ['watchman']).status === 0;

  if (process.platform === 'darwin' && !watchmanExists) {
    var watcherDetails = _crossSpawn2.default.sync('sysctl', ['kern.maxfiles']).stdout.toString();
    if (parseInt(watcherDetails.split(':')[1].trim()) < 5242880) { // <--------------
      _log2.default.withTimestamp(_chalk2.default.red('Unable to start server') + '\nSee https://git.io/v5vcn for more information, either install watchman or run the following snippet:\n' + _chalk2.default.cyan('  sudo sysctl -w kern.maxfiles=5242880\n  sudo sysctl -w kern.maxfilesperproc=524288') + '\n        ');
      process.exit(1);
    }
  } else if (!watchmanExists) {
    try {
      var _watcherDetails = _crossSpawn2.default.sync('sysctl', ['fs.inotify.max_user_watches']).stdout.toString();
      if (parseInt(_watcherDetails.split('=')[1].trim()) < 12288) { // <--------------
        _log2.default.withTimestamp(_chalk2.default.red('Unable to start server') + '\n  See https://git.io/v5vcn for more information, either install watchman or run the following snippet:\n  ' + _chalk2.default.cyan('  sudo sysctl -w fs.inotify.max_user_instances=1024\n    sudo sysctl -w fs.inotify.max_user_watches=12288'));
        process.exit(1);
      }
    } catch (e) {
      _log2.default.withTimestamp('Warning: Unable to run `sysctl fs.inotify.max_user_watches`. If you encounter issues, please refer to https://git.io/v5vcn');
    }
  }
}

Thanks, actually this is what screwed me up – there is a watchman on npm (https://github.com/dfjones/watchman) which does almost exactly the same thing, and not knowing better I didn’t realize this wasn’t the watchman I was supposed to install (and thus my confusion above). Not sure what a good solution is here given the conflicting package names…

I don’t think it should change sysctl config automatically, at least not without asking the user first. And it would require root, which this script shouldn’t have.

Rather I think it should inform the user if there isn’t enough watchers, and print the commands the user should run.

I had the same issue on Ubuntu 16.04. Try to install watchman. If you get some error about watchman when running npm start, see: https://github.com/react-community/create-react-native-app/issues/51

As mentioned by @kevz93 I’m thinking of adding a part where it sets the inotify(linux) or kern(macOS) watches and raising a PR. I’m thinking of adding that part here https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/src/util/packager.js#L63. @brentvatne @dikaiosune Please let me know if it’s the place to add.

Note: Adding sudo will ask user to enter the password. I don’t know if it’s okay to do that.

@ide the notice doesn’t say anything about using brew either install watchman or run the following snippet

@vinniejames You should install Watchman from Homebrew per the instructions, not npm.

I ran into the same trouble o a brand new High Sierra install. The notice regarding installing watchman is a bit misleading as that package has been deprecated I tried installing fb-watchman globally, which didnt help either

➜  coinfox-mobile git:(master) ✗ npm start

> coinfox-mobile@0.1.0 start /Users/vince/Sites/coinfox-mobile
> react-native-scripts start

10:37:01 AM: Unable to start server
See https://git.io/v5vcn for more information, either install watchman or run the following snippet:
  sudo sysctl -w kern.maxfiles=5242880
  sudo sysctl -w kern.maxfilesperproc=524288

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! coinfox-mobile@0.1.0 start: `react-native-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the coinfox-mobile@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/vince/.npm/_logs/2018-03-03T18_37_01_339Z-debug.log
➜  coinfox-mobile git:(master) ✗ sudo sysctl -w kern.maxfiles=5242880
Password:
kern.maxfiles: 49152 -> 5242880
➜  coinfox-mobile git:(master) ✗ sudo sysctl -w kern.maxfilesperproc=524288
kern.maxfilesperproc: 24576 -> 524288

@anp Please could you link to watchman? I think the “install watchman” error message should include this link.

Did you call your app reactNative by any chance? 😃

@festiveox: 10000 might not be enough. Try to increase it more.

@k3a yes I figured out after some research hehe. Although I appreciate your answer, you can see I fixed my error using those two commands, which are the equivalents for OSX, which I agree with @vs1682 they should be added to the start script 😃