main.jsbundle does not exist. This must be a bug with.. main.jsbundle issue after upgrading to react-native 0.63

Viewed 21436

"react": "16.13.1", "react-native": "0.63.0",

Encountered the below main.jsbundle does not exist. This must be a bug with issue when trying to archive after upgrading to react-native 0.63. was wondering if anyone encounters the same issue

enter image description here

13 Answers

This worked for me in a project involving babel-plugin-module-resolver:

  1. Open your ios/*.xcworkspace in Xcode.
  2. Click on the name of your project in the project navigator.
  3. Click on the name of your target in the pane on the left.
  4. Click on Build Phases.
  5. Expand the Bundle React Native code and images phase.
  6. On the first line of the script, add cd $PROJECT_DIR/.. to go up a directory.

The whole script should look like this:

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.

Props to @typester for bringing this up on facebook/react-native #29351.

Found a solution

  1. In Xcode Build Phases -> Copy Bundle Resources, add main.jsbundle

enter image description here

  1. In package.json, add
"scripts": {
    "bundle:ios": "react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios",
    "postinstall": "yarn run bundle:ios"
    ...
  },

so the main.jsbundle will be generated

For me the error occurred because I had imports like this:

import Component from '..';

Replacing those with relative paths (@components/path/to/component) fixed the issue.

Not sure why resolving these paths is problematic now.

I dug into the node_modules/react-native/node_modules/@react-native-community/cli/build/commands/bundle/buildBundle.js and placed a catch block in the buildBundle function in order to see the component(s) with the problematic import.

I think @changey's solution also works, it only requires adding an additional build step in the CI.

Change your babel.config.js to .babelrc.js and it will work

I upgraded from 0.62.5 to 0.63 and encountered the same error.

In my case, I found out the react-native-xcode.sh script executed in the "Bundle React Native code and images" build phase passed the wrong entry file (index.js) to the build command when it should have used index.ios.js. Not sure exactly why this changed in 0.63.

A solution that worked for me was specifying the correct entry file when running the script:

  1. In Xcode, go to Build Phases -> Bundle React Native code and images
  2. Change this part of the script ../node_modules/react-native/scripts/react-native-xcode.sh to ENTRY_FILE=index.ios.js ../node_modules/react-native/scripts/react-native-xcode.sh

Seen similar issue with RN v0.63. Looking at the error logs noticed that the was an issue with Node memory out of range (EG failed to build bundle). I fixed this by adding:

export NODE_OPTIONS=--max_old_space_size=1024

to Bundle React Native code and images phase script

EG:

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

if you use M1'series Mac, you can try below.

  1. select Xcode Build Phases tab
  2. expand the Bundle React Native code and images phase
  3. change script like below
cd $PROJECT_DIR/..
export NODE_BINARY=/opt/homebrew/bin/node
./node_modules/react-native/scripts/react-native-xcode.sh

operation image

As I ran yarn bundle-ios, the following message showed up.

Unable to resolve module config/dimension from src/scenes/Home/index.js: config/dimension could not be found within the project.

I've been using react-native-module-resolver。 I configed "@configs" for path alias。 As you can see above the @ is missing。

Corrected it, main.jsbundle was created, finally。

For me, I had .babelrc and babel.config.js files in the same project. So RN could not find certain imported libraries. So l modified my .babelrc this way:

 {
   "extends": "./babel.config.js", 
   "plugins": [ //bla bla 

   ],
 }

this was how the error stopped for me.

This error is specific to the architecture settings of the Xcode project itself. When the wrong arch is set, you'll receive this error because the bundle failed to build.

Here is an updated answer for anyone receiving this error on Xcode 12.5+

Remove Cache, Reinstall Libraries, and Update Pods

Sometimes this error is purely due to cache referencing a different architecture. Use the react-native-clean-project utility to reset all cache related to the project, reinstall packages, and updates pods. This usually clears up the majority of my missing bundle errors.

Verify Xcode Build Settings (Xcode 12.5+ on x86_64)

For Production: you only need to make sure the Architectures settings set to Standard Architectures (default ${ARCHS_STANDARD}). Excluded Architectures should be empty, and if VALID_ARCHS exists, be sure to rename it, then click Archive.

Simulator: You still need to add the VALID_ARCHS variable for the simulator, but set it to the project's workspace, setting the value to x86_64. In order to keep it a single setting for the entire project, make sure VALID_ARCHS isn't already set in Pods project or the App project. If it is, remove the variable, and then set the value on the workspace. Click Run to start your simulation build.

Now when you need to build for production, simply rename VALID_ARCHS to SIM_VALID_ARCHS, and then Archive.

If you have a non-standard Node.js installation, select your project in Xcode, find 'Build Phases' - 'Bundle React Native code and images' and change NODE_BINARY to an absolute path to your node executable. You can find it by invoking 'which node' in the terminal.

Related