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

iOS main.jsbundle does not exists – Bundle React Native code and images #25522

Closed
carloscuesta opened this issue Jul 6, 2019 · 34 comments
Closed
Labels
Bug Component: Image Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@carloscuesta
Copy link
Contributor

carloscuesta commented Jul 6, 2019

Hello!

I have updated an app from react-native@0.55.4 to react-native@0.59.9 and I'm having problems with the iOS build step Bundle React Native code and images. The problem is that when the build gets on this step on the CI machine, fails automatically throwing the following error:

'error: File /Users/travis/Library/Developer/Xcode/DerivedData/app-arslyffdnfsjkgdxahmrdswzporu/Build/Intermediates.noindex/ArchiveIntermediates/app/BuildProductsPath/Release-iphoneos/appName.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'

What bothers me is the thing that I can make a bundle on the CI machine using the react-native bundle command without any problems or issues So I can safely assume that there's no problem with the bundle creation.

Screen Shot 2019-07-06 at 09 39 58

From what I've read at #18472, I tried the proposed solutions such as ensuring that the version of node it's specified by nvm as default, tried to use another version of Xcode, tried to use a newer version of Node. Nothing fixed the problem. Also I've tried to debug the issue and seems that this command it's not being executed. The thing is that this script itself doesn't give any output of what happened on success or fail.

Screen Shot 2019-07-06 at 09 29 49

"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \
$CONFIG_ARG \
--entry-file "$ENTRY_FILE" \
--platform ios \
--dev $DEV \
--reset-cache \
--bundle-output "$BUNDLE_FILE" \
--assets-dest "$DEST" \
$EXTRA_PACKAGER_ARGS

This is the error log:

Screen Shot 2019-07-06 at 09 26 33

React Native Environment

I'm running the builds on a Travis CI machine and before the bump to 0.59.9 this never happened.

info 
  React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: (2) x64 Intel(R) Xeon(R) CPU E5-2697 v2 @ 2.70GHz
      Memory: 1.94 GB / 4.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
      Yarn: 1.16.0 - ~/.yarn/bin/yarn
      npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    IDEs:
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.9 => 0.59.9 

Steps To Reproduce

  1. Run the following command:
xcodebuild -scheme projectName -project ./ios/projectName.xcodeproj -configuration Release -destination 'generic/platform=iOS' -archivePath /Users/travis/Library/Developer/Xcode/Archives/2019-07-06/AppName\ 2019-07-06\ 07.16.44.xcarchive -UseModernBuildSystem=NO archive | tee /Users/travis/Library/Logs/gym/AppName-projectName.log | xcpretty

Describe what you expected to happen:

I expect that the main.jsbundle file is created successfully through the step of Bundle React Native code and images as it does if I do it manually using the react-native bundle command.

Thanks 🙏

@react-native-bot react-native-bot added Component: Image Platform: iOS iOS applications. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. labels Jul 6, 2019
@carloscuesta
Copy link
Contributor Author

After debugging out the issue, I found the problem, leaving it here just in case could help anyone:

On Xcode at the Bundle React Native code and images Build Phase I've set up the NODE_BINARY to the result of which node.

Then the CI finds always the correct binary regardless the node install method.

export NODE_BINARY=$(which node)

Screen Shot 2019-07-08 at 00 36 56

@CaptainJeff
Copy link

CaptainJeff commented Sep 13, 2019

@carloscuesta that didn't work for me but removing the entire Bundle React Native code and images build phase did work

@carloscuesta
Copy link
Contributor Author

carloscuesta commented Sep 14, 2019

But removing the whole step is not a solution since it’s required I guess for building the application.

It has a purpose, otherwise won’t be set at the build step

@CaptainJeff
Copy link

@carloscuesta

You are very right. I just didn't get the build error and thought it fixed it.

Any idea why your solution didn't work for me or anything you think I should test out?

@carloscuesta
Copy link
Contributor Author

Maybe you have another problem that's not related with the bundling itself, can you bundle your application in your local machine with this step ?

Take a look at #18472 @CaptainJeff

@jaumevn
Copy link

jaumevn commented Oct 7, 2019

I've got this problem upgrading react-native to 0.61.1. The build only fails when using Travis CI, compiling locally works perfectly. Did any of you find a solution?

@carloscuesta
Copy link
Contributor Author

Yes, I was having the exact same problem as you @jaumevn this solved the issue: #25522 (comment)

@jaumevn
Copy link

jaumevn commented Oct 7, 2019

Thanks, I've just tried it and works..!

@anniewey
Copy link

@carloscuesta Do you still run react-native bundle to generate the main.jsbundle manually? Or just plainly using which node fix?

@carloscuesta
Copy link
Contributor Author

Just plainly using which node @anniewey

@git-sid-go
Copy link

After debugging out the issue, I found the problem, leaving it here just in case could help anyone:

On Xcode at the Bundle React Native code and images Build Phase I've set up the NODE_BINARY to the result of which node.

Then the CI finds always the correct binary regardless the node install method.

export NODE_BINARY=$(which node)
Screen Shot 2019-07-08 at 00 36 56

This worked for me after trying out so many other options. Thank you so much!

@StijnCoolen
Copy link

StijnCoolen commented Jan 22, 2020

@carloscuesta what does your .travis.yml (or other CI config) look like? Do you use nvm there?

@carloscuesta
Copy link
Contributor Author

Not really @StijnCoolen

On the OS X machine I use the following configuration:

language: node_js
node_js: 10.16.2
os: osx
osx_image: xcode10.1

@stanjhae
Copy link

In my case, I found it's because I'm using typescript.

Open Project > Build Phases > Bundle React Native code and images.
Original look like this

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

this gives me this error: The resource /Users/stanjhae/Desktop/*project-name*/index.js was not found

Apparently, by default it checks for an index.js file but since i'm using index.ts, it goes berzerk.

I explicitly stated it should use index.ts and everything works fine

export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh index.ts

@aeskafi
Copy link

aeskafi commented Feb 22, 2020

After debugging out the issue, I found the problem, leaving it here just in case could help anyone:

On Xcode at the Bundle React Native code and images Build Phase I've set up the NODE_BINARY to the result of which node.

Then the CI finds always the correct binary regardless the node install method.

export NODE_BINARY=$(which node)
Screen Shot 2019-07-08 at 00 36 56

Awesome, Thank bro @carloscuesta #25522 (comment)

@tusharpandey
Copy link

tusharpandey commented Feb 23, 2020

$(which node) is not working in rn-0.61.5

& still I am facing this issue ,
react-native -v
react-native-cli: 2.0.1
react-native: 0.61.5

@BDomantas
Copy link

$(which node) is not working in rn-0.61.5

& still I am facing this issue ,
react-native -v
react-native-cli: 2.0.1
react-native: 0.61.5

I suggest just running the script in Bundle React Native code and images manually and seeing what the issue is.

In my case the step had ../node_modules/react-native/scripts/react-native-xcode.sh script. I ran this script and saw that it looked for index.js, but as I was using TypeScript and had called my file index.ts and that was the reason why it failed

@almeynman
Copy link

I renamed index.ios.js and index.android.js to .ts. Renaming back fixed the issue

@Natkarock
Copy link

$(which node) is not working in rn-0.61.5

& still I am facing this issue ,
react-native -v
react-native-cli: 2.0.1
react-native: 0.61.5

Hello! Did you found a solution? I have rn 0.61.5 too

@dhiv-nitt
Copy link

@carloscuesta Do you still run react-native bundle to generate the main.jsbundle manually? Or just plainly using which node fix?

I ran the bundle command and then built it again and it worked for me !

@vicary
Copy link
Contributor

vicary commented Apr 28, 2020

@stanjhae @BDomantas Specifying the entry file fixes the issue for me, thanks!

This kinda need a fix on the React Native side because TypeScript users tend to go pure and rename whatever .js into .ts(x) but it all goes will until the first iOS release build.

In fact the first thing I did after react-native init --template react-native-template-typescript is to rename that index.js!

I believe we all dug deep and changed all these files,

  1. build.gradle#entryFile
  2. MainApplication.java#getMainJsBundleName
  3. AppDelegate.m#sourceForBridge

But react-native-xcode.sh should really read the entry file from a sensible place such as package.json#main.

@leandrosimoes
Copy link

I was stuck with this problem for a while but after taking a quick look to the react-native-xcode.sh file, I realised that you can set the $ENTRY_FILE variable in the build phase script, like this:

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

In my case, I just set the index.tsx file as my entry file as you can see and everything worked fine.

@vicary
Copy link
Contributor

vicary commented Jul 8, 2020

In my recent upgrade to 0.62 the shell script now complains about the argument, I kind of make the error disappear by changing react-native-xcode.sh index.tsx to react-native-xcode.sh — index.tsx but I doubt it will work at release builds.

I bet the way @leandrosimoes does it is now the only workaround.

@rishisingh-dev
Copy link

Upgraded react native version to 0.63.0 and build failed.
Tried all solutions here but no luck yet. ;(

@GreenRidingHood
Copy link

i know this is sounds silly but my

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

that one has one dot (./node) before node, i didn't pay attention, need to be double dot (../node)

React Native Environment Info:
System:
OS: macOS 10.15.5
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.5.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.5 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6626763
Xcode: 11.6/11E708 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: ^0.59.10 => 0.59.10
npmGlobalPackages:
react-native-cli: 2.0.1

@eurobob
Copy link

eurobob commented Jul 20, 2020

Also upgraded to 0.63.0 and started having this issue. I managed to get the bundle in by using this command:

react-native bundle --entry-file='index.js' --bundle-output='./ios/app/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'

However, my archived app does not contain the assets from my src folder. Everything works fine on development build

@narayananramu
Copy link

For those still running into issues in React Native 0.63: #18472 (comment)

@knifedge
Copy link

if you are using module-resolver

  • Expand the Bundle React Native code and images phase.
  • Replace the script with the following

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


Note that this might break if the source of this is a bug in 0.63.0, so you may need to undo this on a future release.

@theLastCc
Copy link

Also upgraded to 0.63.0 and started having this issue. I managed to get the bundle in by using this command:

react-native bundle --entry-file='index.js' --bundle-output='./ios/app/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'

However, my archived app does not contain the assets from my src folder. Everything works fine on development build

I was having the same problem as you. I can bundle the app.But LaunchScreen.storyboard can't load the launchImage.

@Gregoirevda
Copy link
Contributor

The only way I managed to solve this issue is by archiving the app locally in XCode to find the problem.
Product -> Destination -> Generic IOS device
Product -> Archive

Looking at the logs will show you the exact problem.

Something must be wrong on the JS side (for me, babel-plugin-import-graphql wasn't working with metro during archive).
This issue means it didn't found main.jsbundle, because there was an issue while generating the JS and there can be many reasons for that, so debugging locally should help you.

(I reverted all changes made to the build phase in this thread)

@vrgimael
Copy link

vrgimael commented Sep 15, 2020

None of the above fixed it for me on 0.63.2, but it works with this PR, it'll probably be released soon #29477

@justcodejs
Copy link

I also faced the same issue and try to amend the script file or the Bundle React Native code and images section in XCode also didn't help.

I found that there are two versions of node js installed in my Macbook. One located in the /opt/local/bin (ver 10) and the other one located in /usr/local/bin (version 12). My bash shell is using the /opt/local/bin by default. When I try to update the node to latest version (14.14) it only update the version located in /usr/local/bin.

End up, I edit my bash shell profile in $HOME/.bash_profile to add in the /usr/local/bin into my PATH environment variable as below.

export PATH="/usr/local/bin:${PATH}"

After edit the profile, I try to run the app via command line npx react-native run-ios but the system complaint that it unable to locate the sharp npm module. I remove the sharp folder under the node_modules and run yarn again to reinstall the sharp module.

After that, I restart XCode again and archive the project again and managed to completed the archiving without any issue.

Hope my finding will help other with similar issue.

Good luck!
JustCode
https://www.youtube.com/channel/UCBBvKaJQEoBKww71zN7vutg

@GustavoMSevero
Copy link

@carloscuesta I tried to do that, but I get this erros

Command PhaseScriptExecution failed with a nonzero exit code

@StevenChandra
Copy link

In my cases, I change crypto-js library version from 4.0.0 to 3.3.0 in package json and everything worked.
main.jsbundle not a problem anymore

@facebook facebook locked as resolved and limited conversation to collaborators Oct 11, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: Image Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

No branches or pull requests