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

Error Building the app in release mode "main.jsbundle does not exist" #36886

Closed
MohammedWaheeb opened this issue Apr 12, 2023 · 24 comments
Closed
Labels
📦Bundler Needs: Author Feedback Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@MohammedWaheeb
Copy link

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(R) Xeon(R) 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

@blakef
Copy link
Contributor

blakef commented Apr 13, 2023

I can't reproduce it using these steps:

npx react-native@latest init RN0716 --version 0.71.6
cd RN0716/ios
bundle install && bundle exec pod install
npx react-native run-ios --configuration Release

CleanShot 2023-04-13 at 11 51 34

@github-actions
Copy link

github-actions bot commented May 7, 2023

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label May 7, 2023
@segebee
Copy link

segebee commented May 9, 2023

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

@github-actions github-actions bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label May 9, 2023
@github-actions
Copy link

github-actions bot commented Jun 3, 2023

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 3, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@viettranbhtech
Copy link

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

@sportakal
Copy link

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.

@usedlife
Copy link

usedlife commented Jul 6, 2023

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.

@usedlife
Copy link

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

@ajayranga
Copy link

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.

@amorimcode
Copy link

I need to run
react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'

everytime im creating archive, please some tips?

@segebee
Copy link

segebee commented Feb 4, 2024

It solved our issue... but I do not know if we still do that for every build

I need to run react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'

everytime im creating archive, please some tips?

@usedlife
Copy link

usedlife commented Feb 5, 2024

I need to run react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'

everytime im creating archive, please some tips?

react-native repo will automatically bundle when create iOS archive

@ItaloVCosta
Copy link

After I forced Xcode to use the same Node.js version as my project, this issue stopped happening. To force the Node.js version, I simply set the default version to the correct one using the command:

nvm alias default 12.22.12

@segebee
Copy link

segebee commented Feb 18, 2024

After I forced Xcode to use the same Node.js version as my project, this issue stopped happening. To force the Node.js version, I simply set the default version to the correct one using the command:

nvm alias default 12.22.12

thanks for sharing

@khawarzaman001
Copy link

khawarzaman001 commented Feb 20, 2024

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 :)

@edcity-charlie
Copy link

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

@roancoetzee
Copy link

roancoetzee commented Feb 27, 2024

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.

@tux2nicolae
Copy link

tux2nicolae commented Feb 27, 2024

@roancoetzee you won't believe it, but you already helped someone (10h from your comment).

Thank you, for pointing it out! Just noticed the same thing even on the latest react native version (0.73.5).

p.s if you find out why it wasn't set, please share with us as well :)

@VitDev17
Copy link

@roancoetzee You are super on point here! Can you explain to us how you came to this solution? What was the debugging process?
Thank you a lot my man!

@roancoetzee
Copy link

@VitDev17 Glad it helped. Debugging wise it wasn't anything special. In xcode you can view the build logs by doing
View -> Navigator -> Reports or cmd + 9

The error appeared under the Run custom shell script 'Bundle React Native code and images' job in the right panel which pointed me in the direction of the script. There I played around with the script by using echos to figure out what was going on.

@e3bmo3ty
Copy link

e3bmo3ty commented Mar 14, 2024

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.

@roancoetzee thanks, after hours of debugging this is the only solution works for me

@duirron
Copy link

duirron commented May 3, 2024

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.

this help-me with error "Make sure you're running a packager server or have included a .jsbundle file in your application bundle." Thank you man.

@React-RN-Pratik
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦Bundler Needs: Author Feedback Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests