React Native: XCode: Build failed with error "EMFILE: too many open files, watch"

Viewed 2584

– MackBook Air M1 – macOS 11.3 – XCode 12.5 – react native 0.64.1 – node 16.0.0 – npm 7.15.1 – watchman 2021.05.31.00

When I try to archive a project or build one for a device, Xcode stops building with an error:

/Users/aptyp/Projects/Proffmylife/Client/node_modules/metro-hermes-compiler/src/emhermesc.js:81
          throw ex;
          ^

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/aptyp/Projects/Proffmylife/Client/node_modules/sane/src/node_watcher.js:143:12)
    at FSWatcher.emit (node:events:365:28)
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}
Command PhaseScriptExecution failed with a nonzero exit code

But for the simulator, the build works fine.

I have tried to reinstall node_modules, Pods, watchman with brew. Also I've created files limit.maxfiles.plist, limit.maxproc.plist into dir /Library/LaunchDaemons/ and now ulimit -a shows processes 2000 and file descriptors 524288. Restarting computer and unlock Keychain.

On my PC with Hackintosh I don't have this problem.

2 Answers

I created a new project with the same name, installed all the latest packages and copied the code. Only after that the project was built success.

Related