Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Apple M1] Don't compile on IOS metro-hermes-compiler too many open files #668

Closed
alexanderoskin opened this issue Apr 25, 2021 · 15 comments

Comments

@alexanderoskin
Copy link

Bug Description

  • Hermes version: 0.7.2
  • React Native version: 0.64.0
  • OS version: macOS 11.2.3
  • Platform: arm64 (Apple M1)

Steps To Reproduce

  1. Update existing project from 0.63.4 to 0.64.0
  2. Compile with Xcode

The Expected Behavior

Pre-version compiles fine

Error Message


Showing All Messages
+ PACKAGER_SOURCEMAP_FILE=

+ [[ '' == true ]]

+ /Users/alexander/Code/Sputnik/sputnik-app/node_modules/@sentry/cli/sentry-cli /Users/alexander/Code/Sputnik/sputnik-app/node_modules/react-native/cli.js bundle --entry-file index.js --platform ios --dev false --reset-cache --bundle-output /Users/alexander/Library/Developer/Xcode/DerivedData/SputnikApp-fjypaeaptflxsubdwkhkfnnxdzqv/Build/Products/Release-iphonesimulator/main.jsbundle --assets-dest $'/Users/alexander/Library/Developer/Xcode/DerivedData/SputnikApp-fjypaeaptflxsubdwkhkfnnxdzqv/Build/Products/Release-iphonesimulator/\320\241\320\277\321\203\321\202\320\275\320\270\320\272.app' --sourcemap-output /Users/alexander/Library/Developer/Xcode/DerivedData/SputnikApp-fjypaeaptflxsubdwkhkfnnxdzqv/Build/Intermediates.noindex/SputnikApp.build/Release-iphonesimulator/SputnikApp.build/DerivedSources/main.jsbundle.map

                    Welcome to Metro!

              Fast - Scalable - Integrated

/Users/alexander/Code/Sputnik/sputnik-app/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/alexander/Code/Sputnik/sputnik-app/node_modules/sane/src/node_watcher.js:143:12)
    at FSWatcher.emit (node:events:369:20)
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}
the transform cache was reset.
Command PhaseScriptExecution failed with a nonzero exit code

Additional Info

Newly created React Native project is being compiled successfully. The issue only with a existing project.

@gedeagas
Copy link

+1 i also get this error on M1

warning: the transform cache was reset.
                    Welcome to Metro!
              Fast - Scalable - Integrated


/Users/gedeagas/Work/Kumparan/kumparan-mobile-app/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/gedeagas/Work/Kumparan/kumparan-mobile-app/node_modules/sane/src/node_watcher.js:143:12)
    at FSWatcher.emit (node:events:378:20)
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}

@ddevilcore
Copy link

Same problem

@owinter86
Copy link

try deleting the yarn.lock file and peforming yarn install

@JonnyBurger
Copy link

fsevents is the module that causes it to break. Upgrade fsevents to fix it:

// yarn.lock
fsevents@^2.1.2:
-  version "2.1.3"
-  resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e"
-  integrity sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==
+  version "2.3.2"
+  resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
+  integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

@alexanderoskin
Copy link
Author

@JonnyBurger @owinter86 fsevents upgrade to 2.1.3 works like a charm, many thanks.

@majirosstefan
Copy link

only doing this does not always help

@endkeyCoder
Copy link

fsevents is the module that causes it to break. Upgrade fsevents to fix it:

// yarn.lock
fsevents@^2.1.2:
-  version "2.1.3"
-  resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e"
-  integrity sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==
+  version "2.3.2"
+  resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
+  integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

you save me, tks bro!

@skanger
Copy link

skanger commented Nov 28, 2022

fsevents is the module that causes it to break. Upgrade fsevents to fix it:

// yarn.lock
fsevents@^2.1.2:
-  version "2.1.3"
-  resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e"
-  integrity sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==
+  version "2.3.2"
+  resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
+  integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

not working, after reinstall 'watchman', upgrade fsevent.

it can be debug on simulator, but not archive.

any solution?

@skanger
Copy link

skanger commented Nov 28, 2022

node version v12, v14, v16, v18 all failed.
output:
Failed to construct transformer: TypeError: fsevents is not a function at new FSEventsWatcher (/Users/boywus/easyspark/f/node_modules/metro/node_modules/jest-haste-map/build/lib/FSEventsWatcher.js:162:20) at createWatcher (/Users/boywus/easyspark/f/node_modules/metro/node_modules/jest-haste-map/build/index.js:1052:23) at Array.map (<anonymous>) at HasteMap._watch (/Users/boywus/easyspark/f/node_modules/metro/node_modules/jest-haste-map/build/index.js:1230:44) at /Users/boywus/easyspark/f/node_modules/metro/node_modules/jest-haste-map/build/index.js:517:21 at Generator.next (<anonymous>) at asyncGeneratorStep (/Users/boywus/easyspark/f/node_modules/metro/node_modules/jest-haste-map/build/index.js:193:24) at _next (/Users/boywus/easyspark/f/node_modules/metro/node_modules/jest-haste-map/build/index.js:213:9) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:95:5)

@JuxhinB
Copy link

JuxhinB commented Nov 30, 2022

upgrading fsevent didn't helped me either

my output is

      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/juxhin/Projects/openbar_frontend/node_modules/sane/src/node_watcher.js:143: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
}```

@DanielT777
Copy link

DanielT777 commented Dec 2, 2022

                 Welcome to React Native!
                Learn once, write anywhere


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

Error: EMFILE: too many open files, watch
    at FSWatcher._handle.onchange (node:internal/fs/watchers:204:21)
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.checkedEmitError (/Users/*/Desktop/*/*/node_modules/sane/src/node_watcher.js:143:12)
    at FSWatcher.emit (node:events:513:28)
    at FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}

Node.js v18.12.1
main.jsbundle does not exist. This must be a bug with
+ echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'

Same here, on M1 Pro, Ventura 13, XCode 14.1
already: upgraded watchman, fsevent.

@robhogan
Copy link
Contributor

robhogan commented Dec 2, 2022

There are a couple of issues conflated here I think.

  1. The previous minimum version of fsevents had no M1 build available, so some existing projects may have included a version of fsevents incompatible with their machine, causing Metro to fall back from macOS-native to a less optimised Node JS watcher. Clearing/updating your lockfile (as suggested above) would've fixed this, and we bumped the minimum for future RN versions:
  1. "Too many open files" is not an M1-specific issue. That's coming up against the configured limits of macOS, whose FSEvents API is used under the hood by fsevents, Watchman, and Node itself. Perhaps try one/both of the approaches below and please do let us know what works for you:

Use a combined kqueue+fsevents watcher

Newer versions of Watchman allow the use of a combined FSEvents + kqueue watch strategy to reduce the load on FSEvents (similar to newer versions of Node's fs.watch). You can try that mode by installing the latest version of Watchman from Homebrew and adding this line to your .watchmanconfig (create it in your project root if it doesn't exist already):

{
  "watcher": "kqueue+fsevents"
}

Verify that you're using this watcher backend with watchman watch-project /absolute/path/to/your/project/root on the command line. You should see watcher: "kqueue+fsevents" in the output. Ensure you don't have useWatchman: false in your Metro config, and hopefully this will help.

Raise system limits on open file descriptors

Ensure you are using Watchman, and follow instructions below to raise the watch limits on your machine:

Put the following into a file named /etc/sysctl.conf on macOS to cause these values to persist across reboots:

kern.maxfiles=10485760
kern.maxfilesperproc=1048576

Source: https://facebook.github.io/watchman/docs/install.html#macos-file-descriptor-limits

@eliot-ye
Copy link

eliot-ye commented Apr 4, 2023

                 Welcome to React Native!
                Learn once, write anywhere


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

Error: EMFILE: too many open files, watch
    at FSWatcher._handle.onchange (node:internal/fs/watchers:204:21)
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.checkedEmitError (/Users/danieltirrier/Desktop/APPSPANEL/azap-react/node_modules/sane/src/node_watcher.js:143:12)
    at FSWatcher.emit (node:events:513:28)
    at FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}

Node.js v18.12.1
main.jsbundle does not exist. This must be a bug with
+ echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'

Same here, on M1 Pro, Ventura 13, XCode 14.1 already: upgraded watchman, fsevent.

/node_modules/react-native/scripts/react-native-xcode.sh add export PATH=/opt/homebrew/bin:$PATH work for me

@dalbeer22g
Copy link

fsevents is the module that causes it to break. Upgrade fsevents to fix it:

// yarn.lock
fsevents@^2.1.2:
-  version "2.1.3"
-  resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e"
-  integrity sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==
+  version "2.3.2"
+  resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
+  integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

not working, after reinstall 'watchman', upgrade fsevent.

it can be debug on simulator, but not archive.

any solution?

@skanger did you find any solution?

@lastant
Copy link

lastant commented Jul 5, 2023

Tried everything and realized there was no fsevents in my node_modules (even though it's a newly properly created react native project), did 'npm install fsevents' and this solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests