react-native: RN 0.63.4 main.jsbundle does not exist. This must be a bug with'

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

App won’t build for release scheme, therefore won’t archive. I have watchman installed. I can build for debug, just not release.

React Native version:

0.63.4 Node version is v14.15.5

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Build for Release scheme

Expected Results

For the build to succeed

Snack, code example, screenshot, or link to a repository:

During the build process…

BUNDLE_FILE=/Users/coltrane/Library/Developer/Xcode/DerivedData/mobile-dsdtbnudpwicuuckveptihmuzeuy/Build/Products/Release-iphonesimulator/mobile.app/main.jsbundle
+ /usr/local/bin/node /Users/coltrane/Documents/Apps/Storyboard/social/mobile/node_modules/react-native/cli.js bundle --entry-file index.js --platform ios --dev false --reset-cache --bundle-output /Users/coltrane/Library/Developer/Xcode/DerivedData/mobile-dsdtbnudpwicuuckveptihmuzeuy/Build/Products/Release-iphonesimulator/mobile.app/main.jsbundle --assets-dest /Users/coltrane/Library/Developer/Xcode/DerivedData/mobile-dsdtbnudpwicuuckveptihmuzeuy/Build/Products/Release-iphonesimulator/mobile.app
warning: the transform cache was reset.
                 Welcome to React Native!
                Learn once, write anywhere


events.js:292
      throw er; // Unhandled 'error' event

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 (/Users/coltrane/Documents/Apps/Storyboard/social/mobile/node_modules/sane/src/node_watcher.js:143:12)
    at FSWatcher.emit (events.js:315:20)
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:184:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}
+ [[ false != true ]]
+ [[ ! -f /Users/coltrane/Library/Developer/Xcode/DerivedData/mobile-dsdtbnudpwicuuckveptihmuzeuy/Build/Products/Release-iphonesimulator/mobile.app/main.jsbundle ]]
echo 'error: File /Users/coltrane/Library/Developer/Xcode/DerivedData/mobile-dsdtbnudpwicuuckveptihmuzeuy/Build/Products/Release-iphonesimulator/mobile.app/main.jsbundle does not exist. This must be a bug with'

In my build phases, I have it set to

export NODE_BINARY=$(which node)
../node_modules/react-native/scripts/react-native-xcode.sh

I’ve tried:

cd $PROJECT_DIR/..
export NODE_BINARY=node
./node_modules/react-native/scripts/react-native-xcode.sh

and other variations of the solutions on issue #29351 which didn’t work either.

Please help!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 11
  • Comments: 25 (1 by maintainers)

Most upvoted comments

I found the issue on my end. It was because of my $PATH environment variable, which was set to /opt/homebrew/bin for zsh, but not configured for /bin/sh. This path is used by the metro bundler to identify the presence of watchman; that’s why the reported error was symptomatic of a missing watchman install! (thanks @safaiyeh ).

I. Generic solution with path_helper

path_helper is a very handy utility shipped with MacOS to construct the PATH environment for any shell, and it’s the Apple recommended way to share a path globally. To add a path, you just need to create a new file under /etc/paths.d/ with one or more lines containing each a path:

sudo -s 'echo "/opt/homebrew/bin" > /etc/paths.d/200-homebrew'

Unfortunately, /bin/sh run from XCode 12.4 doesn’t seem to source /etc/profile which in turns should call path_helper, but we can force this behavior by sourcing it ourselves. Add these lines in the very beginning of “Bundle React native code and images” build phase script:

if [ -f /etc/profile ]; then
    . /etc/profile
fi
export NODE_BINARY=node
...

II. Quick and dirty fix

An alternative is to hardcode the homebrew path in the shell script. I find it less generic but certainly straightforwards. Add this line in the very beginning of “Bundle React native code and images” build phase script:

export PATH="$PATH:/opt/homebrew/bin"
export NODE_BINARY=node
...

Above “II. Quick and dirty fix” :

export PATH="$PATH:/opt/homebrew/bin"
export NODE_BINARY=node
...

did the job in my case.

I have this issue from time to time, but only when running archive. Sometimes it’s working for a few days, and then I have to reinstall node, watchmen, brew, switch between node versions (10-15) and sometimes it just click and works. and than - after next 1-3 weeks it doesn’t work once again 😃

I think somehow sometimes Xcode CLI when building archive can’t run watchman. Buildng debug on simulator/physical works fine, only the archive is problematic.

I work it:

touch ios/main.jsbundle

npx react-native run-ios

Open project ios folder in Xcode, goto build phases in Copy Bundle Resources tab remove main.jsbundle Screenshot 2022-06-16 at 5 36 39 PM

same here