metro icon indicating copy to clipboard operation
metro copied to clipboard

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

Open superoskin opened this issue 5 years ago • 19 comments

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.

superoskin avatar Apr 25 '21 14:04 superoskin

+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
}

gedeagas avatar Apr 27 '21 08:04 gedeagas

Same problem

ddevilcore avatar May 04 '21 11:05 ddevilcore

try deleting the yarn.lock file and peforming yarn install

oliverwinter-vdb avatar May 17 '21 10:05 oliverwinter-vdb

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==

JonnyBurger avatar May 20 '21 13:05 JonnyBurger

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

superoskin avatar May 21 '21 20:05 superoskin

only doing this does not always help

majirosstefan avatar Apr 26 '22 16:04 majirosstefan

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!

endkeyCoder avatar Aug 31 '22 20:08 endkeyCoder

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 avatar Nov 28 '22 16:11 skanger

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
}```

JuxhinB avatar Nov 30 '22 20:11 JuxhinB

                 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.

DanielT777 avatar Dec 02 '22 10:12 DanielT777

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:
  • https://github.com/facebook/metro/pull/875 (Metro 0.73 / RN 0.71)
  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

robhogan avatar Dec 02 '22 11:12 robhogan

                 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

eliot-ye avatar Apr 04 '23 02:04 eliot-ye

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?

dalbeer22g avatar Jun 08 '23 05:06 dalbeer22g

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.

lastant avatar Jul 05 '23 14:07 lastant

Thanks, it works for me on rn v.0.74 and node 18.14.2

michalnatkanski avatar Jul 23 '24 09:07 michalnatkanski

Running into this again on node 20, any new fix in 2024?

codinsonn avatar Aug 27 '24 07:08 codinsonn

Thanks, it works for me on rn v.0.75.3 and node 20.17.0.

maxlxq avatar Sep 23 '24 05:09 maxlxq

npm install fsevents fixed mine, RN team, this problem still exist now Dec 2024.

grandwaterman avatar Dec 02 '24 00:12 grandwaterman

What worked for me, I changed my node version to 18.17.0 then I deleted the node_modules folder then re-install using npm i

Propulse1 avatar Dec 28 '24 18:12 Propulse1