DEV Community

Ziyi Chu
Ziyi Chu

Posted on

How to fix the: "EMFILE: too many open files, watch" error in macOS

I've tried to build a react-native project on my MacBook Pro, but when running the command:

npx react-native start
Enter fullscreen mode Exit fullscreen mode

I get the error:

Error: EMFILE: too many open files, watch
Enter fullscreen mode Exit fullscreen mode

There are several solutions online, but they are scattered, so I am here to summarize.

Solution1: watchman

brew install watchman
Enter fullscreen mode Exit fullscreen mode

The watchman utility enables React-Native to watch file changes.

Solution 2: change Node.js version with nvm

Run the command below to check the Node version:

nvm current
Enter fullscreen mode Exit fullscreen mode

Switch Node version by:

nvm install --<the node version>
nvm use <version_number>
Enter fullscreen mode Exit fullscreen mode

For example:

nvm install 12.18.3
nvm use 12.18.3
Enter fullscreen mode Exit fullscreen mode

To see all Node versions you've installed, use:

nvm ls
Enter fullscreen mode Exit fullscreen mode

To see all published Node versions, use:

nvm ls-remote
Enter fullscreen mode Exit fullscreen mode

Usually, we should try several versions. Newest(v22.8.0), new(v20.0), and old (v17.3). This should solve the problem.

Reference:
1.https://flaviocopes.com/react-native-emfile-too-many-open-files/
2.https://flatirons.com/blog/how-to-set-a-default-node-version-with-nvm/
3.https://blog.logrocket.com/how-switch-node-js-versions-nvm/

Top comments (0)