This repository has been archived by the owner. It is now read-only.

Start script hangs without error when there are no available inotify watches #234

Closed
trygveaa opened this Issue Jun 2, 2017 · 59 comments

Comments

Projects
None yet
@trygveaa

trygveaa commented Jun 2, 2017

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.

@brentvatne

This comment was marked as outdated.

Member

brentvatne commented Jun 2, 2017

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

@brentvatne brentvatne added the bug label Jun 2, 2017

@nimir

This comment was marked as outdated.

nimir commented Jun 20, 2017

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:

  • npm ls react-native-scripts: react-native-scripts@0.0.31
  • npm ls react-native: react-native@0.44.3
  • npm ls expo: expo@17.0.0
  • node -v: v6.9.5
  • npm -v: 5.0.3
  • yarn --version: Not installed
  • watchman version: 4.7.0

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!

@thinq4yourself

This comment was marked as outdated.

thinq4yourself commented Jun 22, 2017

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

@k3a

This comment was marked as outdated.

k3a commented Jul 3, 2017

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

@s417-lama

This comment was marked as outdated.

s417-lama commented Jul 4, 2017

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: #51

@tetralix

This comment was marked as outdated.

tetralix commented Jul 8, 2017

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

@k3a

This comment has been minimized.

k3a commented Jul 8, 2017

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

@tetralix

This comment was marked as outdated.

tetralix commented Jul 8, 2017

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

@luffs

This comment has been minimized.

luffs commented Jul 10, 2017

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

@penniath

This comment was marked as outdated.

penniath commented Aug 1, 2017

Thanks @k3a, you saved my day!

@akshaynaik404

This comment was marked as outdated.

akshaynaik404 commented Aug 1, 2017

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.

@ashishrvtech

This comment was marked as outdated.

ashishrvtech commented Aug 2, 2017

@k3a It works thanks!!!

@darkguy2008

This comment was marked as outdated.

darkguy2008 commented Aug 5, 2017

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

This comment was marked as outdated.

Contributor

vs1682 commented Aug 6, 2017

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

@kevz93

This comment was marked as outdated.

kevz93 commented Aug 8, 2017

The command should be part of the start script.

@k3a

This comment was marked as outdated.

k3a commented Aug 11, 2017

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

@darkguy2008

This comment was marked as outdated.

darkguy2008 commented Aug 11, 2017

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

@vs1682

This comment was marked as outdated.

Contributor

vs1682 commented Aug 12, 2017

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.

@trygveaa

This comment was marked as outdated.

trygveaa commented Aug 12, 2017

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.

@vs1682

This comment was marked as outdated.

Contributor

vs1682 commented Aug 12, 2017

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

@nickjuntilla

This comment was marked as resolved.

nickjuntilla commented Aug 12, 2017

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.

@nickjuntilla

This comment was marked as resolved.

nickjuntilla commented Aug 12, 2017

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.

@k3a

This comment was marked as outdated.

k3a commented Aug 12, 2017

@vs1682

This comment was marked as resolved.

Contributor

vs1682 commented Aug 13, 2017

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.

@darkguy2008

This comment was marked as resolved.

darkguy2008 commented Aug 13, 2017

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

@vs1682

This comment was marked as resolved.

Contributor

vs1682 commented Aug 13, 2017

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

@sathiz

This comment was marked as outdated.

sathiz commented Oct 5, 2017

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!

@tiongshunooi

This comment was marked as outdated.

tiongshunooi commented Nov 9, 2017

+1 to have an error message...

@Meekohi

This comment was marked as outdated.

Meekohi commented Nov 9, 2017

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?

@anp

This comment was marked as outdated.

Member

anp commented Nov 13, 2017

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

@Meekohi

This comment was marked as outdated.

Meekohi commented Nov 13, 2017

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

@lrvlr

This comment was marked as outdated.

lrvlr commented Nov 14, 2017

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:

testing@0.1.0 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: react-native-scripts@1.7.0 
npm ls react-native: react-native@0.49.5 
npm ls expo: expo@22.0.3 
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?

@brentvatne

This comment was marked as outdated.

Member

brentvatne commented Nov 15, 2017

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

@cyan33

This comment has been minimized.

cyan33 commented Nov 26, 2017

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.

@willnwhite

This comment was marked as outdated.

willnwhite commented Dec 28, 2017

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

@willnwhite

This comment was marked as outdated.

willnwhite commented Dec 29, 2017

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

@Meekohi

This comment was marked as outdated.

Meekohi commented Dec 29, 2017

@alper

This comment was marked as outdated.

alper commented Jan 5, 2018

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

@Meekohi

This comment was marked as outdated.

Meekohi commented Jan 5, 2018

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

@jsstrn

This comment has been minimized.

jsstrn commented Jan 30, 2018

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.

@sendsent

This comment was marked as outdated.

sendsent commented Feb 6, 2018

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

@Kristories

This comment was marked as outdated.

Kristories commented Feb 14, 2018

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

This comment was marked as outdated.

vinniejames commented Mar 3, 2018

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

This comment was marked as outdated.

Member

ide commented Mar 3, 2018

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

@vinniejames

This comment was marked as outdated.

vinniejames commented Mar 3, 2018

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

@ide

This comment was marked as resolved.

Member

ide commented Mar 3, 2018

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

@AndresCuervo

This comment has been minimized.

AndresCuervo commented Mar 14, 2018

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.

@geoffreywiseman

This comment has been minimized.

geoffreywiseman commented Mar 19, 2018

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

This comment was marked as off-topic.

noodlebreak commented May 3, 2018

Nothing worked for me...

npm ls react-native-scripts - react-native-scripts@1.14.0 

npm ls react-native - react-native@0.55.3 

npm ls expo - expo@27.0.1 

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

> billi@0.1.0 start /home/ash/projects/myproject
> react-native-scripts start

01:09:56: Starting packager...

@DStt

This comment was marked as off-topic.

DStt commented May 30, 2018

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

On running npm start

> mobile-flashcards@0.1.0 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?

@willxy

This comment has been minimized.

willxy commented Jun 10, 2018

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.

@anp

This comment has been minimized.

Member

anp commented Jun 13, 2018

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

@react-community react-community locked as resolved and limited conversation to collaborators Jun 13, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.