watchman: EMFILE: too many open files, watch

i’m facing below issue while generating archive in xcode

node:events:371
      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 NodeWatcher.checkedEmitError (/Users/igesia/work/mobile/igesia_mobile/node_modules/sane/src/node_watcher.js:143:12)
    at FSWatcher.emit (node:events:394:28)
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}

i’m on 2021.06.07.00 version of watchman

any idea how to fix this?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 30
  • Comments: 44

Most upvoted comments

I was able to solve this issue on a new M1 Macbook Air by just installing watchman directly with ARM version of brew (the one at /opt/homebrew/bin/brew) and tweaking the file descriptor sizes.

brew install watchman
sudo launchctl limit maxfiles 16384 16384 && ulimit -n 16384

I didn’t have to change anything else.

i solved this error by following below steps

  1. clone your repo into some separate location
  2. run npm i
  3. reset all caches by running this command cd ios && rm -rf ~/Library/Caches/CocoaPods Pods ~/Library/Developer/Xcode/DerivedData/\*; pod deintegrate; pod setup; pod install --repo-update

This Work for Me

https://stackoverflow.com/a/70177808/6455789

just add this line only image

I was also stuck in this error This works for me run this command globally

brew install watchman

I was also facing this issue while building archive in Xcode in my M1 Mac. Fortunately, it had resolved after following these steps:

  1. Install Rosetta2 & Homebrew in non-rosetta mode terminal from the following StackOverflow link

  2. Add this brew to the PATH or you can CD into /usr/local/Homebrew/bin and run ./brew install watchman

  3. In XCode, Go to Target > Build Settings > Architectures > Exclude Architectures. And add these two key-value pairs.

m1

Same problem here with the same version 2021.06.07.00 on an Apple Silicon Macbook (m1).

But in my case, there is a slight nuance (I don’t know if it’s your case too @deepakverma4):

  • If I run metro from a terminal running in Rosetta mode, with watchman installed using x86_64 brew (/usr/local/Homebrew), no problem to bundle my javascript files.
  • If I run metro from a regular terminal (without Rosetta mode), with watchman installed using arm64 brew (/opt/homebrew), I get the EMFILE: too many open files error

Knowing that I tried a lot of random things like increasing a lot the ulimit in:

  • Start Packager XCode script
  • Bundle React Native code XCode script
  • In a terminal before running manually metro
  • In launchctl using sudo launchctl limit maxfiles 65536 unlimited

But nothing worked. 😕

i had the same problem with my M1 and a React Native project i tried to build/archive in Xcode. i first had to xcode-select --install but it gave me an estimate of 120 hours so i downloaded it manually from apple. Afterwards i could finally do brew install watchman, still had the error while i was trying to build/archive in xcode. After some debugging i found out that Xcode still didnt recognize watchman because it wasnt in its path. (For debugging measures i went to Target -> Build Phases -> Bundle React Native code and images and added a line watchman --version to check if watchman was recognized) After finding out it didnt, i added to the first line the path to my homebrew. export PATH=/opt/homebrew/bin:$PATH Then it finally worked 😃

If anyone has problems with apple m1, there is a solution that works to me first install apple command line: xcode-select --install then install watchman: brew install watchman That’s all

The above steps to clear cache didn’t work for me.

  • If I run metro from a terminal running in Rosetta mode, with watchman installed using x86_64 brew (/usr/local/Homebrew), no problem to bundle my javascript files.
  • If I run metro from a regular terminal (without Rosetta mode), with watchman installed using arm64 brew (/opt/homebrew), I get the EMFILE: too many open files error

Thanks so much for this, installing watchman using x86_64 brew and adding it to my PATH let me build the app. Additionally, I had to follow this to get watchman working: https://github.com/facebook/watchman/issues/640#issuecomment-416983649

Thanks to @techniqs, I fixed my issue by adding export PATH=/opt/homebrew/bin:$PATH in the Build Phases > Bundle React Native code & images section.

NOTE: Using RN: 0.71.3

set -e

export PATH=/opt/homebrew/bin:$PATH <---- add this line here

WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"

The reason is that Xcode runs a clean shell for build tasks, so any PATH updates done in your profile (e.g. ~/.zshrc) are not sourced and therefore Xcode cannot see the binaries installed via brew (in /opt/homebrew/bin)

in my case , downgrading node from v14 to v12 solved the issue

I was also facing this issue while building archive in Xcode in my M1 Mac. Fortunately, it had resolved after following these steps:

  1. Install Rosetta2 & Homebrew in non-rosetta mode terminal from the following StackOverflow link
  2. Add this brew to the PATH or you can CD into /usr/local/Homebrew/bin and run ./brew install watchman

Hi Salim95,

Thanks for sharing!! Now I can archive in x code

just to reshare, the StackOverflow answer I follow is https://stackoverflow.com/a/64997047/14657391

I came across this error as well

This works for me

xcode-select --install

brew install watchman

thanks to the comments above!

in my case, I just moved my rn project folder to the root folder or /users/{name}

UNCHECKED

If you are running your terminal with “Open using Rosetta”, then having Xcode “Open using Rosetta” must also be checked and vice versa. This way depending on how people install Watchman (either with arch -arm64 or otherwise) then everything should coalesce.

So, running terminal with “Open using Rosetta”, then installing Watchman via arch -arm64 brew install watchman, then running Xcode with “Open using Rosetta” should work.

arch -arm64 brew install watchman

Thanks to @techniqs, I fixed my issue by adding export PATH=/opt/homebrew/bin:$PATH in the Build Phases > Bundle React Native code & images section.

NOTE: Using RN: 0.71.3

set -e

export PATH=/opt/homebrew/bin:$PATH <---- add this line here

WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"

The reason is that Xcode runs a clean shell for build tasks, so any PATH updates done in your profile (e.g. ~/.zshrc) are not sourced and therefore Xcode cannot see the binaries installed via brew (in /opt/homebrew/bin)

Wow, so thats the reason why “too many files” issue reoccurred after Xcode being updated in my case!! Good to know that, finally relieved! 😄

brew install watchman on Mac M1 solved the issue for me. Did not have to specify the arch.

rm -rf node_modules && npm install – > worked for me in android