Goglides Dev 🌱

Cover image for Solving EMFILE Error in React Native with Watchman
Balkrishna Pandey
Balkrishna Pandey

Posted on

Solving EMFILE Error in React Native with Watchman

While working on a React Native project, I encountered a frustrating error that prevented my app from running on iOS. The error log is as follows:

bkpandey@Balkrishnas-MacBook-Pro medvisor % npm run ios    

> [email protected] ios
> expo start --ios

Starting project at /Users/bkpandey/Documents/workspace/code/dmeo/medvisor
Starting Metro Bundler
› Opening exp:// on iPhone 12
⠦ Fetching Expo Gonode:events:497
      throw er; // Unhandled 'error' event

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:207:21)
Emitted 'error' event on NodeWatcher instance at:
    at FSWatcher._checkedEmitError (/Users/bkpandey/Documents/workspace/code/dmeo/medvisor/node_modules/metro-file-map/src/watchers/NodeWatcher.js:82:12)
    at FSWatcher.emit (node:events:519:28)
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:213:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null

Node.js v20.14.0
Enter fullscreen mode Exit fullscreen mode

Understanding the EMFILE Error

The EMFILE error occurs when the system exceeds the maximum number of file descriptors it can open simultaneously. This is a common issue in large projects with many files.

Introducing Watchman

Watchman is a tool developed by Facebook for watching changes in the filesystem. It is designed to handle large codebases efficiently and helps in avoiding the EMFILE error by optimizing the way file changes are monitored.

Resolving the Issue with Watchman

To resolve the EMFILE error, you can install Watchman, which Metro (the JavaScript bundler for React Native) can utilize to manage file watching more efficiently.


To install Watchman on macOS, use Homebrew:

brew install watchman
Enter fullscreen mode Exit fullscreen mode

Try running the project again the issue disappeared magically!

npm run ios
Enter fullscreen mode Exit fullscreen mode

npm run ios

Top comments (0)