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)
Fix for “EMFILE: too many open files” Issue in Expo on macOS
If you’re encountering the
EMFILE: too many open files, watcherror in Expo on macOS, follow these steps to fix the issue:Step 1: Install
watchmanFirst, make sure that
watchmanis installed:Step 2: Increase the Watcher Limit
Ensure that the watch limit is properly set:
Step 3: Delete
node_modulesandpackage-lock.jsonDelete the
node_modulesdirectory andpackage-lock.jsonfile to ensure a fresh installation of packages:Step 4: Install Packages
Install the dependencies again:
Step 5: Upgrade
watchman(If Needed)Make sure
watchmanis up-to-date:Step 6: Create
metro.config.jsCreate a
metro.config.jsfile in the root of your project and add the following configuration:Step 7: Shutdown
watchmanStop the
watchmanserver:Step 8: Clear Expo’s Cache
Clear Expo’s cache to reset any internal issues:
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:
And nope, I don’t have
fseventsin mynode_modules.It looks like
watchmanis not initiated.Just running the the
watchmancommand, 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
This step is important. Thank you for your attention to this information!
Sometimes it’s not about
watchmaneven 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
nodeinPATHfor the Xcode environment.Xcode -> Build Phases -> Scroll down to “Bundle React Native code and images”, and add
nodetoPATH:export PATH=$PATH:/opt/homebrew/binIn case your
nodeis 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 nodeshould tell you the path.export PATH=$PATH:/path/to/your/node/folderFixed 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 .