main.jsbundle does not exist. This must be a bug with'

10.5k views Asked by At

I keep getting this errror when i'm trying to run React native app from Xcode 13.3 .

if i run it from terminal ( react-native run-ios ) it works fine.

Please find enclosed error details.

>     > File /Users/Library/Developer/Xcode/DerivedData/appName-crvjvqqnpdxpwkfkxccvnxunhhkw/
Build/Products/Release-iphonesimulator/appName.app/main.jsbundle
> does not exist. This must be a bug with'
My Environment details

MAC OS - 12.3.1 (M1 chip)
Xcode - 13.3
command line tools - 13.3
RN version - 0.61.5

solutions i have tried upto now

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

(Xcode) -Build Phases -> Bundle React Native code and images , change to

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

Please let me know how i can fix this error.

6

There are 6 answers

0
JJuras On

I encountered this issue all of a sudden after ~1 year of development on a project, working in RN 0.71.6, currently on Version 14.3.1 (14E300c). I tried to upgrade to the latest version of v71 - RN 0.71.14, but the problem persisted. It seemed intuitive that since this issue 'crept in', simply refreshing my build environment should solve it.

I tried to reinstall all libraries to no avail. Cleaning the build folder also did not work.

Solution:
Delete the project state/metadata directory that contains the Build output folder.

By entirely deleting /Users/<username>/Library/Developer/Xcode/DerivedData/<app-id>-<unique-build-hash-id>, I was able to build a completely fresh version of the app, and the problem with the missing main.js file was resolved.

Project settings/options are cached elsewhere, so there is no need to worry about losing these. You will need to re-index files though (for-example), and any other build-prep that your project would encounter with a fresh start on the repository.

Note:
When clearing the build folder via XCode, only the following directory is nuked: /Users/<username>/Library/Developer/Xcode/DerivedData/<app-id>-<unique-build-hash-id>/Build/Product. And some contents of /Users/<username>/Library/Developer/Xcode/DerivedData/<app-id>-<unique-build-hash-id>/Build/Intermediates.noindex are modified.

For my case, the issue seemed to result in a corrupted or incorrect state persisted in the files generated by xcode that describe the project's build setup, which are not cleared when the build folder is cleared.

0
elsurudo On

This could be any number of things. Check your Xcode build logs to see why the bundle build failed. In my case, I had an import in my react code that wasn't resolving.

0
Stanislau Buzunko On

I faced this issue when I updated node v18 from v16. Switching back to v16 fixed the error. React-native 0.62.2

0
kurtis_dev On

This issue has gone on for years but the most common fix I find is the below.

Run this command at the project root level:

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

Then in build phases in xcode > click 'copy bundle resources' > click the '+' symbol > click 'add other...' > select the newly generated main.jsbundle file in projectname/ios > and tick box for copy contents. Now clean build folder then archive again.

If you have Images also you'll need to add the folder for assets into the same location as the above.

Hope that helps :)

1
Tho Nguyen On

This was resolve in 0.63.3. https://github.com/facebook/react-native/issues/29351

If you still have issue with higher version, pls try to run react-native bundle command manually.

1
benek On

Run

sudo xcode-select --reset

Then run (check if you use index.js or index.tsx or other)

npx react-native bundle --entry-file ./index.js --platform ios --bundle-output ios/main.jsbundle --assets-dest ios

main.jsbundle should appear in your ios folder.

enter image description here

Then you can add it to "Copy Bundle Resources"below section:

enter image description here enter image description here