react-native: Error Building the app in release mode "main.jsbundle does not exist"

Description

We are building a react native application and we are facing this issue sometimes, without any changes building can work or fail

`▸ Running script ‘Bundle React Native code and images’ the transform cache was reset.

❌ error: File /Users/runner/Library/Developer/Xcode/DerivedData/-eulgfyrcmjmgohfphedrvfvwygma/Build/Products/Release-iphoneos/***.app/main.jsbundle does not exist. This must be a bug with React Native, please report it here: https://github.com/facebook/react-native/issues

▸ Generating ‘**********.app.dSYM’ ** BUILD FAILED **

The following build commands failed: PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/runner/Library/Developer/Xcode/DerivedData/-eulgfyrcmjmgohfphedrvfvwygma/Build/Intermediates.noindex/**********.build/Release-iphoneos/.build/Script-00DD1BFF1BD5951E806B06BC.sh (1 failure) ##[error]Error: /usr/bin/xcodebuild failed with return code: 65`

th

React Native Version

0.71.6

Output of npx react-native info

System: OS: macOS 12.6.4 CPU: (3) x64 Intel® Xeon® CPU E5-1650 v2 @ 3.50GHz Memory: 5.16 GB / 14.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 16.16.0 - ~/hostedtoolcache/node/16.16.0/x64/bin/node Yarn: 1.22.19 - ~/.yarn/bin/yarn npm: 8.11.0 - ~/hostedtoolcache/node/16.16.0/x64/bin/npm Watchman: Not Found Managers: CocoaPods: 1.12.0 - /usr/local/lib/ruby/gems/3.0.0/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 Android SDK: API Levels: 27, 28, 29, 30, 31, 32, 33, 33, 33 Build Tools: 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.1, 28.0.2, 28.0.3, 29.0.0, 29.0.1, 29.0.2, 29.0.3, 30.0.0, 30.0.1, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 33.0.0, 33.0.1, 33.0.2 Android NDK: 25.2.9519653 IDEs: Android Studio: Not Found Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: 1.8.0_362 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.6 => 0.71.6 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

Build the app, in an azure pipeline enviroemnt, and its not stable on my local machine, I get

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

npx react-native run-ios --configuration Release

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 24 (1 by maintainers)

Most upvoted comments

Posting my experiece since it might help someone else. react-native: 0.70.15 xcode: 15.1

I had a look at the script responsible for building the main.jsbundle at node_modules/react-native/scripts/react-native-xcode.sh. The script was failling on this line "$HERMES_CLI_PATH" -emit-binary $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE".

To get to this line USE_HERMES would need to be anything but false. Since we haven’t swapped over to hermes yet and we explicitly set hermes_enabled => false in our PODS file, I expected that USE_HERMES would be false. However when I echoed USE_HERMES, it resulted in being empty. This meant that the check if [[ $USE_HERMES == false ]] would fail and the code for a hermes enabled environment would be run, which is not what we want.

I haven’t figure out why USE_HERMES is not being set but as temp workaround I am setting it manually in Bundle React Native code and images like below.

Screenshot 2024-02-26 at 10 48 01

If anyone knows why USE_HERMES is not getting set let me know.

export PATH=/opt/homebrew/bin:$PATH export NODE_BINARY=node …/node_modules/react-native/scripts/react-native-xcode.sh

Add the following lines in build phases under “Bundle React Native Code and Images” Hope it will remove the error 😃

I had this same issue

Realized it was because I changed the index.js file to index.tsx

Discovered this error by adding the below to package.json

"build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'"

and running yarn build:ios or npm run build:ios

Hi same issue after updating react-native to 0.72.4 from 0.70.5. Able to fix it by build:ios command but I need to run the build:ios command every time before creating ios archive. Which was not default behavior. Please let know if there is any other fix for this.

export PATH=/opt/homebrew/bin:$PATH export NODE_BINARY=node …/node_modules/react-native/scripts/react-native-xcode.sh

Add the following lines in build phases under “Bundle React Native Code and Images” Hope it will remove the error 😃

I appreciate your response, as it is very useful for my React-Native version 0.63.4.

I solved it with this: #34768 (comment)

background with me: I use nvm to manage the node version, and the system default node version is very low (<12).

When packaging mainbundle.js, /bin/sh uses the default node version, resulting in a syntax error exception. image

The key to the solution is to use the correct node version when packaging.

And the official documentation has given the hint:

https://reactnative.dev/docs/environment-setup?guide=native#optional-configuring-your-environment

image

I solved it with this: https://github.com/facebook/react-native/issues/34768#issuecomment-1256895362

background with me: I use nvm to manage the node version, and the system default node version is very low (<12).

When packaging mainbundle.js, /bin/sh uses the default node version, resulting in a syntax error exception. image

The key to the solution is to use the correct node version when packaging.

I had to update export NODE_BINARY=/usr/local/bin/node in ios/.xcode.env and it worked. My project had same issue after upgrading to new RN 0.71.7

export PATH=/opt/homebrew/bin:$PATH export NODE_BINARY=node …/node_modules/react-native/scripts/react-native-xcode.sh

Add the following lines in build phases under “Bundle React Native Code and Images” Hope it will remove the error 😃

Thanks for sharing, it works in my trial. My project is an expo project and native build with XCode. My XCode version is Version 15.2 (15C500b) My expo version is 49

I had to update export NODE_BINARY=/usr/local/bin/node in ios/.xcode.env and it worked. My project had same issue after upgrading to new RN 0.71.7

Thanks for resolution. It works for me with a minor difference.

My node binary was /opt/homebrew/bin/node. I found it run command -v nodein terminal.

Hope helps to other.