EMFile: too many open files, watch - building Release react native iOS app
Asked Answered
Z

2

7

I wrote my React Native app using Expo, and then ejected it using expo eject. I am now trying to build release versions of the app. It works fine for Android, and also for debug builds for iOS, but when I try to build for release on Xcode I get the following error:

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:178:28)
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.checkedEmitError (/node_modules/sane/src/node_watcher.js:143:12)
    at FSWatcher.emit (events.js:400:28)
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:184:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}

I have seen a few other people with similar errors, and tried the following steps with no luck:

  • tried different versions of node
  • updated watchman
  • reinstalled homebrew
  • closed all windows/application apart from Xcode

I have a feeling the error is to do with the M1 chip, but am really struggling to find a solution, so any help is appreciated.


Device - Mac mini (M1, 2020), running macOS Monterey 12.0.1

Node Version - 17.0.1

React Native Version - ~0.63.4

I used this article for setting up the environment

Let me know if you require anymore information/snippets

Zoezoeller answered 24/11, 2021 at 17:26 Comment(0)
C
1

I had the same issue earlier this year. It was indeed because of the M1 chip and XCode not building properly when watchman was installed without Rosetta.

I was building on an M1 Mac using XCode 12.5 and had to:

  • Install watchman on using an x86_64 instance of homebrew
  • Run the metro server in a Rosetta terminal
  • Run XCode without Rosetta

If this is the first time you're installing a package using the x86_64 instance of homebrew remember to add it to your PATH.

Catsup answered 8/12, 2021 at 14:3 Comment(2)
Thank you, will give this a try. Is the x86_64 homebrew the M1 one? If not, do you have any links to how to install this. And then when you say run metro server, do you just mean npm start in a terminal while the app is building?Zoezoeller
The x86_64 instance of homebrew is one installed using a Rosetta terminal (not the default ARM one that M1 macs use). Yes its a simple npm start in the terminal but run it before building the app in xcode.Catsup
D
0

We can solve this issue by the following commands

brew install watchman

sudo launchctl limit maxfiles 16384 16384 && ulimit -n 16384
Dee answered 20/8, 2022 at 1:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.