18
votes

"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

10
In my case this seems to be related to using babel-plugin-module-resolver for short absolute imports. Looking closer at the build logs, I can see that it fails to generate the jsbundle the first time it hits one of these imports. I haven't found a solution yet. I assume going back to relative imports would work... - Isaac Overacker
@IsaacOveracker Same exact situation here. I wonder if it's this plugin in particular that's not working for some reason, or if other babel functionality isn't working too. - EmpireJones
@EmpireJones I noticed that I had the default generated .babelrc file in addition to a babel.config.js where I had configured the babel-plugin-module-resolver settings. I removed .babelrc and got further in generating the jsbundle, but ran into a different error related to my monorepo nohoist rules missing a few libs. Why this only fails on 0.63.0 and not 0.62.2 is still eluding me. I've made it a bit further, but now I have errors similar to Sachanski's answer--relative imports. - Isaac Overacker
@EmpireJones I found a solution. See my answer below. - Isaac Overacker

10 Answers

17
votes

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.

10
votes

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

2
votes

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.

2
votes

None of the above fixed it for me, but it works with this PR, it'll probably be released soon https://github.com/facebook/react-native/pull/29477

Just in case somebody finds it useful :)

1
votes

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
0
votes

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

0
votes

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。

0
votes

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.

0
votes

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. 🎉