metro: Error: EMFILE: too many open files, watch

Bug Report I upgraded the app to the new arch (0.76.x) and now I am getting this error when trying to archive in xcode:


node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:204:21)
Emitted 'error' event on NodeWatcher instance at:
    at FSWatcher._checkedEmitError (node_modules/metro-file-map/src/watchers/NodeWatcher.js:82:12)
    at FSWatcher.emit (node:events:513:28)
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}

What is the current behavior? App works fine, in dev as well as in release mode on both android as well as in iOS. First i was getting this error in terminal too when running npm start but that was fixed by deleting node_modules and reinstalling deps but archiving is still throwing this error.

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test. Set Run scheme to Release and change run destination to Any iOS device, and try to archive.

What is the expected behavior? Archive should be executed successfully instead of throwing a metro bundler error.

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system. metro - v0.81.0 node - v22.11.0 npm - v10.9.0 react-native - 0.76

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

Fix for “EMFILE: too many open files” Issue in Expo on macOS

If you’re encountering the EMFILE: too many open files, watch error in Expo on macOS, follow these steps to fix the issue:

Step 1: Install watchman

First, make sure that watchman is installed:

brew install watchman

Step 2: Increase the Watcher Limit

Ensure that the watch limit is properly set:

ulimit -n 9999999

Step 3: Delete node_modules and package-lock.json

Delete the node_modules directory and package-lock.json file to ensure a fresh installation of packages:

rm -rf node_modules && rm package-lock.json

Step 4: Install Packages

Install the dependencies again:

npm install

Step 5: Upgrade watchman (If Needed)

Make sure watchman is up-to-date:

brew upgrade watchman

Step 6: Create metro.config.js

Create a metro.config.js file in the root of your project and add the following configuration:

const exclusionList = require('metro-config/src/defaults/exclusionList');

module.exports = {
  resolver: {
    blockList: exclusionList([
      /node_modules/,
      /build/
    ])
  }
};

Step 7: Shutdown watchman

Stop the watchman server:

watchman shutdown-server

Step 8: Clear Expo’s Cache

Clear Expo’s cache to reset any internal issues:

expo start -c

This should resolve the “too many open files” issue in Expo. Let me know if you face any other problems!

I’m facing the same error:

node:events:502
      throw er; // Unhandled 'error' event
      ^

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

Node.js v22.13.0

And nope, I don’t have fsevents in my node_modules.

It looks like watchman is not initiated.

Just running the the watchman command, with no arguments or whatsoever, fixes it. But it happens again next time I restart the computer (MacOS).

My fix: downgrade node version from v23.9.0 to -> v18.20.7 reinstall node_modules, run and enjoy!

agree

export PATH=$PATH:/path/to/your/node/folder

This step is important. Thank you for your attention to this information!

Sometimes it’s not about watchman even if the error tells that:

If you’ve already tried everything (restart, clean build, watchman install, watchman reinstall, increase watcher limit etc…), your case might be similar to mine, and you don’t have node in PATH for the Xcode environment.

Xcode -> Build Phases -> Scroll down to “Bundle React Native code and images”, and add node to PATH: export PATH=$PATH:/opt/homebrew/bin

In case your node is in a different path (e.g. you installed it with nvm), check your node’s PATH and add it to PATH like above.

To check your node’s path, open terminal and which node should tell you the path.

export PATH=$PATH:/path/to/your/node/folder

Fixed it by upgrading all the packages (except react, kept it at 18.x as react native doesn’t support 19.x yet), though my packages were just a little behind the latest versions, it worked, deleted node_modules, pods and resintalled them .