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

Created on 2 Jun 2017  ·  59Comments  ·  Source: expo/create-react-native-app

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

> [email protected] 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:

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.

bug

Most helpful comment

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

All 59 comments

It seems pretty reasonable to handle this error with a useful message as you described, as well as, of course, to not hang but to instead show some useful information and exit instead. If anyone is interested in contributing, this is a useful place to look: https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/src/util/packager.js#L55

I've the start script also hanging without error but seems for a different reason as i've already increased my inotify watchers and running react-native start works fine without a problem!

Same project was starting fine yesterday, no changes and it's not working today! My connection seems fine!

Environment:

Also tried:

  • rm -rf node_modules then fresh npm install
  • watchman watch-del-all
  • npm start --clear-cache and npm start --reset-cache

How can i debug this to find what's causing the issue? tried to look at the packager.js and scripts/start.js for verbose flags without luck!

👍 on this 20 day old issue. First go at CRNA for our new app with latest and this happens to us, too.

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

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

@k3a Can you please provide more details how "increase of that sysctl" fixed this issue?

@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.

@k3a I would never figure out that problem is related to user watches parameter. Worked for me, but increased to 12k. OS: Fedora 25

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

Thanks @k3a, you saved my day!

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.

@k3a It works thanks!!!

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

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

The command should be part of the start script.

@darkguy2008 fs.inotify.max_user_watches is Linux-specific sysctl and I mainly use Linux. Mac OS implementation probably uses FSEvents and I don't know if there are any limits. Maybe your problem is somewhere else. You can try debugging it by seeing all system calls. Try dtruss npm start and look for suspicious error return codes.

@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 :)

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.

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.

@trygveaa

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.

Right.

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

I'm actually working on this solution only.

Thanks.

This also happens for me on Sierra 10.12.5. A fresh create react native project works but this one I've been working on will no longer start. I've set all my package.json files back to to how they were with a fresh project, but it's just not working.

**Added info: The only thing I can think to add is I used npm to install firebase and then removed it. My main purpose is to get this working with firebase.

Now I'm getting a very strange error:

2017-08-12 14:50 node[4105] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

Is there a recommended node version number aside from the current stable?

Update got it working with node v6.11.1 -- 8.2.1 is not working.

@Nicholas https://github.com/facebook/react-native/issues/10028 It seems to be related to this issue, try increasing maxfiles (a few comments above)

On August 12, 2017 11:51:32 PM GMT+02:00, Nicholas Juntilla notifications@github.com wrote:

Now I'm getting a very strange error:

2017-08-12 14:50 node[4105] (FSEvents.framework) FSEventStreamStart:
register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

Is there a recommended node version number aside from the current
stable?

--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
https://github.com/react-community/create-react-native-app/issues/234#issuecomment-322008253

Raised a PR #358 to solve this issue.
Please check and let me know.

Note: As I don't have a mac, I was not able to check this for macOS. I would appreciate if someone can do that. Thanks.

@vs1682 I do have one, but I don't know how to test that PR :( if you can guide me, I'll happily test for you.

@darkguy2008 you need to fetch the pull request in your local repo and follow the contribution guide to set it up locally.
Make sure that your system's kern.maxfiles and kern.maxfilesperproc are set to default.

This is happening to me on Unbutu, I try to run sudo sysctl -w fs.inotify.max_user_watches=10000 but it doesn't fix the issue either... any other fix gor this on unbutu? Or anyone else experiencing this?

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

@trygveaa thank you very much I increased it to 120000 and now it's working.

@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

Required 10485760 for me

EDIT: I just realized I named my sample project ReactNative. Is that colliding with the react-native? But now I'm stuck "Building JavaScript bundle..." on my Android phone, while terminal output "Finished building JavaScript bundle in 17111ms".

Well, this isn't going well for me. Using create-react-native-app, I hit this:

5:28:00 PM: 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

"install watchman" is a bit brief. I did "npm install -g watchman", and then re-ran. It did something more, and I was able to use the QR code. But then I get this

jest-haste-map: @providesModule naming collision:
  Duplicate module name: ReactNative
  Paths: /Users/mikeaustin/Projects/ReactNative/node_modules/react-native/Libraries/Renderer/shims/ReactNative.js collides with /Users/mikeaustin/Projects/ReactNative/package.json

This warning is caused by a @providesModule declaration with the same name across two different files.

And the last line on the console, with a red background and error stats on my phone:

5:33:13 PM: Failed building JavaScript bundle

So, this is not easy at all :) I'm familiar with React, and also Xcode but not React Native.

Did you call your app reactNative by any chance? :)

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!

+1 to have an error message...

Could anyone give an ELI5 of what's going on here? If watchman is a dependency why isn't it just included in the first place?

@Meekohi it's...complicated. The main reasons are that watchman isn't distributed via npm, and maintaining our own npm distribution of the binaries would be rather difficult.

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'm so confused and tired over here. I had the same error as @sathiz and @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

I installed watchman, but now it just hangs on:

[email protected] start /.../testing
react-native-scripts start

9:31:05 PM: Starting packager...

I can't make it work.
I've also tried using exp start, it gives me the QR but on my phone I get "failed to complete tunnel connection" and nothing happens.

npm ls react-native-scripts: [email protected] 
npm ls react-native: [email protected] 
npm ls expo: [email protected] 
node -v: v6.12.0
npm -v: 4.6.1
yarn --version: 0.27
watchman version: Please specify a target and action ???
Operating system: Ubuntu 17.04

Can anyone help?

@lrvlr - can you jump onto our slack and dm me? https://slack.expo.io -- I am brent on there

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.

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

@Meekohi, please could you post the link to the right watchman here?

I npm installed watchman but that did not fix this problem.

@alper you can't get the watchman off npm. Get it from Facebook's github as linked above. The npm version is now officially deprecated so you should get a warning.

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.

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

@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');
    }
  }
}

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

> [email protected] 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! [email protected] start: `react-native-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

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

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

C.f. various docs online but it seems the error message should probably be more precise to point people towards Homebrew.

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.

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

Nothing worked for me...

npm ls react-native-scripts - [email protected] 

npm ls react-native - [email protected] 

npm ls expo - [email protected] 

node -v - v8.11.1
npm -v - 5.6.0

yarn --version

The program 'yarn' is currently not installed. You can install it by typing:
sudo apt install cmdtest

# Installed:
 (971)-> yarn --version
0.22

watchman version
watchman: command not found

On running npm start:

 (968)-> npm start

> [email protected] start /home/ash/projects/myproject
> react-native-scripts start

01:09:56: Starting packager...

cat /proc/sys/fs/inotify/max_user_watches
1874919423

On running npm start

> [email protected] start /home/dsa/project/test/mobile-flashcards
> react-native-scripts start
13:40:40: Warning: Unable to run `sysctl fs.inotify.max_user_watches`. If you encounter issues, please refer to https://git.io/v5vcn

I don't receive the warning if i launch it with sudo
Why I have to launch a local npm app with root privileges?

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.

@willxy you're right! Since this issue is apparently showing up in search results for lots of people, I decided to lock this and to hide all comments that don't contain important information for fixing the issue. Hopefully it should be much easier to read the history now. If after installing watchman (NOT using the watchman npm package) and raising inotify/fsevents limits you're still having issues, please open a new issue! Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FezVrasta picture FezVrasta  ·  3Comments

liujb picture liujb  ·  5Comments

iRoachie picture iRoachie  ·  5Comments

noelweichbrodt picture noelweichbrodt  ·  3Comments

jckuhl picture jckuhl  ·  4Comments