0
votes

This question seems to be everywhere on SO, but the answers don't seem to address or answer my situation. I am just getting started with nodejs and react native, so I installed nodejs and ran these commands to get started:

$ npm install expo-cli
$ npm update
$ npx expo init helloWorld

I selected the "minimal" bare workflow and then started with npx expo start. npx couldn't find expo-cli, so I movied the node_modules directory into the helloWorld directory and started again with npx expo start. This time, the project starts okay, but immediately gives me an error about exceeding watchers, most likely due to the large number of files it tries to watch after adding the node_modules dir:

internal/fs/watchers.js:186
    throw error;
    ^

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/drew/helloWorld/node_modules/css-tree'
    at FSWatcher.<computed> (internal/fs/watchers.js:178:26)
    at Object.watch (fs.js:1445:34)
    at NodeWatcher.watchdir (/home/drew/helloWorld/node_modules/sane/src/node_watcher.js:159:22)
    at Walker.<anonymous> (/home/drew/helloWorld/node_modules/sane/src/common.js:109:31)
    at Walker.emit (events.js:315:20)
    at /home/drew/helloWorld/node_modules/walker/lib/walker.js:69:16
    at FSReqCallback.oncomplete (fs.js:163:23) {
  errno: -28,
  syscall: 'watch',
  code: 'ENOSPC',
  path: '/home/drew/helloWorld/node_modules/css-tree',
  filename: '/home/drew/helloWorld/node_modules/css-tree'
}

All of the top answers I found searching for solutions here had to do with watchman, but I don't have that installed and react native seems to be using fs.watch instead. The one relevant question I found suggests that there is no way to add an ignore list like there is in watchman:

Doesn't look like it's possible. Just take a look at the path in the listener and do nothing if it starts with 'node_modules'.

It can't be that much of a performance hit, unless you're constantly updating modules while node is running, which would be a little strange.

Is this not the way I should be setting up my development environment? I want to isolate projects as much as I can (coming from python where virtualenv is very important), but it seems like it's introducing more problems than I was anticipating. How can I fix this without resorting to installing everything globally?

1

1 Answers

0
votes

It looks like you missed a step after npx expo init.

When running npx expo start, and refusing to install expo-cli globally, you should have called npm install --save-dev expo-cli to add it to the dependencies in the helloworld/package.json and to install it in helloworld/node_modules.

The watcher error comes from exhausting the number of "user watches" in inotify: https://linux.die.net/man/2/inotify_add_watch

It can be tuned through sysctl, see relevant details here: https://stackoverflow.com/a/59726128/4173186 — unfortunately, I could not find a description of this sysctl in the Linux kernel documentation.