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 will not create automatically or update without manual react-native bundle #18472

Closed
3 tasks done
nickmccally opened this issue Mar 20, 2018 · 73 comments
Closed
3 tasks done
Labels
Bug Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@nickmccally
Copy link

nickmccally commented Mar 20, 2018

React native is not creating a main.jsbundle for ios automatically. One must manually be created, even though the scheme set as release. The code used to create a bundle manually:
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

Update this exact issue is happening on android now for us as well during our Jenkins build process. We are able to manually bundle using: react-native bundle --entry-file index.js --platform android --dev false --bundle-output android/main.jsbundle --assets-dest android

No errors occur when this is run, and a bundle is created/updated. From this point forward no bundle updates occur. The following is in Bundle React Native code and images:
export NODE_BINARY=node ../node_modules/react-native/scripts/react-native-xcode.sh

Environment

Environment:
OS: macOS High Sierra 10.13.3
Node: 8.9.4
Yarn: 1.3.2
npm: 5.7.1
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
react: ^16.3.0-alpha.1 => 16.3.0-alpha.2
react-native: 0.54.2 => 0.54.2

Steps to Reproduce

I have been experiencing this with an existing project. I even created a new react native project, and opened the xcode project. It shows main.jsbundle as a missing file. I modified the project scheme to Release, and from there -> Build. No main.jsbundle was created in the iOS project folder. One can manually be created with the code above without an error message.

Expected Behavior

A new main.jsbundle would update on build when the following is run: build from xcode OR react-native run-ios --configuration Release

Actual Behavior

No main.jsbundle is created/updated

@react-native-bot react-native-bot added Platform: macOS Building on macOS. Platform: iOS iOS applications. labels Mar 20, 2018
@nickmccally nickmccally changed the title iOS main.jsbundle will not create automatically, or update without manual react-native bundle iOS main.jsbundle will not create automatically or update without manual react-native bundle Mar 20, 2018
@nickmccally
Copy link
Author

We still have to manually create our bundle for iOS, Android bundle is working fine.

@hramos hramos removed the Platform: macOS Building on macOS. label Mar 29, 2018
@yashafromrussia
Copy link

We had the same issue, the file was checked into the iOS project. We had to remove it & add a new build step Bundle React Native code and images:

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

@m-vdb
Copy link

m-vdb commented Jul 6, 2018

Experiencing the same issue (RN version 0.52.2). Ran into it after removing a package with native dependencies (I just removed Realm). I am still struggling to fix it. react-native-xcode.sh is called properly but the bundle is not created (failing at this line).

Edit:
In my case, my issue was 100% linked to #17610
I managed to find out by adding an echo command in react-native-xcode.sh to print the bundling command, and I actually saw the error.

I think that this can fail for various reasons BUT it should definitely display the content of the errors on the screen, otherwise we are just lost when this happens... (and people get confused, add completely different resolution steps on bug reports, etc...)

@jsina
Copy link

jsina commented Jul 25, 2018

@m-vdb I couldn't realize your workaround. in fact my problem is when I run app on simulator with command react-native run-ios everything works fine but when I try to run the app on real device first I have to create the bundle, because bundle not created automatically and even after creating bundle with command react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios' the static images not shows on ios, although everything works fine in Android devices.

@m-vdb
Copy link

m-vdb commented Jul 26, 2018

@jsina you must have another problem that prevents the automatic bundling. Try to debug the execution of react-native-xcode.sh to see what is the problem exactly. Maybe you are missing some ios setup with an external library or something like that. Sadly, the same symptom (bundle not created automatically) has a multitude of possible causes.

@KouSyurei
Copy link

我只想知道为什么明明需要main.jsbundle文件,框架却不自动生成。。。。。

@nickmccally
Copy link
Author

It is my opinion that this should not be such a widespread issue, and there should be solid documentation to resolving this. I will report back when I have resolved our issue, but currently our CI/CD builds are manually running the bundle script. I've read a bit about some having the wrong path to react-native-xcode.sh, but this has never been the case with our project.

@nickmccally
Copy link
Author

nickmccally commented Jul 26, 2018

Update - our CI/CD process is now reverting to an old version of the main.jsbundle on android and requires a separate command to create the bundle. We are using react-native bundle --entry-file index.js --platform android --dev false --bundle-output android/main.jsbundle --assets-dest android in this build process to resolve for it at the moment. We will review further and see why bundling has broken on android as well and report back. This may save some folks research time, as it was a bit hidden on our end.

@jsina
Copy link

jsina commented Jul 27, 2018

My problem is I've install node with fishshell
I've change the Bundle React Native code and image on Build Phases to:

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

then run react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'
now actually I have images on real device.

@mjmasn
Copy link
Contributor

mjmasn commented Aug 2, 2018

We have the same issue building an android app - building 4 or 5 build types with ./gradlew assembleX where X is dev/int/beta/release etc and often some or all of the builds will have the wrong js bundle (an old one magically reappears from the depths of some cache) or the APK will be e.g. 15MB instead of the usual 40MB (presumably by having no js bundle at all) and just crash on start. I've tried many things starting with running ./gradlew clean before each build and using --reset-cache but nothing seems to help. Even deleting the two build directories, running watchman watch-del-all and deleting everything in /tmp seems to have no effect. It's becoming somewhat infuriating!

It appears the bundler is working correctly, as in the generated js and map files are correct but somehow the APK includes an old bundle (from god knows where) or possible none at all (when we have the APKs that crash instantly).

Build issues like this have now consumed ~100 hours of my life since starting work with RN at the start of the year so I'm dying for a way that will guarantee a 100% fresh build of our dev/int/beta/release builds and for it to be reproducible! If I repeat the build enough times it (usually) eventually works but the fact that it can give completely different output without any code being changed is worrying.

Since 0.56 at least running in dev mode locally seems to have mostly been fixed (just the async storage issue once every 20 or so refreshes) but building APKs remains a big problem (possibly even slightly worse since 0.56 but that's just a gut feeling, I don't have any concrete data).

@mjmasn
Copy link
Contributor

mjmasn commented Aug 2, 2018

Just had the APK size issue again where the first build succeeded and the other 3 failed. From diffing the contents of two of the APKs it looks like none of the assets (images) were copied to the failed one. So that's probably a separate issue to the out of date bundle issue...

pd4d10 added a commit to pd4d10/echojs-reader that referenced this issue Aug 28, 2018
@MrHubble
Copy link

@m-vdb where do you see the output of react-native-xcode.sh?

Reference:

I managed to find out by adding an echo command in react-native-xcode.sh to print the bundling command, and I actually saw the error.

@m-vdb
Copy link

m-vdb commented Sep 13, 2018

in the terminal when you build. You can even call the command yourself with the right arguments

@MrHubble
Copy link

Thanks for taking the time to reply. I was building from Xcode and didn't see any of my echo statements in the Xcode console, nor in the terminal that opens for the metro package bundler. Maybe I should have been using react-native run-ios --configuration Release from the terminal and I would have seen the output.

@amirpervaiz086
Copy link

@nickmccally still having the same issue. Using RN 0.57 latest one. I found no main.jsbundle was created so I had to create it manually and after that If any change is made in app.js, it does not reflect in the build unless I create bundle again through the command.

@shinriyo
Copy link

@amirpervaiz086 me too. main.jsbundle didn't create.

@shinriyo
Copy link

how to make main.jsbundle?
I have it node_modules/react-native/scripts/react-native-xcode.sh.

@amirpervaiz086
Copy link

amirpervaiz086 commented Oct 11, 2018

@shinriyo run this command inside project:
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

@amirpervaiz086
Copy link

Also make sure it is added in copy bundle resources also change this in AppDelegate.m
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@“main” withExtension:@“jsbundle”];

@npalethorpe
Copy link

Side note on this issue - I was in the situation where the main.jsbundle wasn't being auto generated on a release build, meaning each time I made a change to my JS I had to re-run the react-native bundle script prior to playing in release (a complete headache to do).

Turns out there is a tick box "Run script only when installing" within Xcode found in 'Build Phases' > 'Bundle React Native code and images' section. I have now unticked this.

I must have ticked this to fix some other issue and forgotten about it! But now the main.jsbundle script is getting rebuilt each time I run through Xcode. Win.

@FrenchMajesty
Copy link

FrenchMajesty commented Dec 5, 2018

In response to @npalethorpe 's solution: Mine was unticked and a bundle was still not being built automatically when the schema was set to Release.

I am on:

  • MacOS Mojave 10.14.1
  • Xcode 10.1
  • React Native 0.56.1

@ObidosDev
Copy link

ObidosDev commented Dec 7, 2018

Hi all. We had almost the same problem. We have spend around 5h. And at some point we realize that xCode use old node version. LOOOL, but excuse me WTF. Do not ask how and why... I just add $NODE_BINARY -v to ../scripts/react-native-xcode.sh and there was v7.10.0. So we close all apps and just set via nvm normal node version (nvm alias default 10.14.1). Also u may restart your computer. So the problem have gone for now. Maybe this will be useful for someone else :)

I am on:

  • MacOS Mojave 10.14.1
  • Xcode 10.1
  • React Native 0.57.3

@foxundermoon
Copy link

foxundermoon commented Dec 29, 2018

  "scripts": {
    ...
    "bundle:ios": "react-native bundle   --entry-file   index.js  --bundle-output ios/bundle/index.jsbundle   --dev  false  --platform ios  --assets-dest  ios",
    "postinstall": "npm run bundle:ios"
  }

change yourself jsbundle file name

@cory-baker
Copy link

in response to @amirpervaiz086 's solution, be sure to restart xcode

@NikitaKis
Copy link

This worked for me
#29351 (comment)

@maxckelly
Copy link

I generated my own ios/main.jsbundle using react-native bundle as per some of the suggestions in this thread, and for some reason had it listed in Copy bundle resources. Deleting the ios/main.jsbundle file and removing it from Copy bundle resources got react-native-xcode.sh running normally again.

@mngyuan - Did you do it in that order? Delete ios/main.jsbundle then remove it from Copy bundle resources? I did the same as you but didn't fix it.

@mateus-cazuza
Copy link

✅ It worked for me.

Open mac settings> network> select your connection> Advanced> Proxies> Automatic Proxy Discoveries (Uncheck).
Captura de Tela 2020-11-30 às 17 20 53

@ybalaev1
Copy link

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

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

@udaysagartammina
Copy link

react-native-cli: 2.0.1
react-native: 0.61.5
node: v13.4.0

"build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'"

Run command : npm run build:ios

main.jsbundle file dose not created, created some extra files like report.20210421.091227.2175.0.001.json

Any one can help me.

@ybalaev1
Copy link

replace
in "build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'"
to "build:ios": "react-native bundle --entry-file=index.js --bundle-output=./ios/main.jsbundle --dev=false --platform=ios"

@udaysagartammina
Copy link

udaysagartammina commented Apr 22, 2021

"build:ios": "react-native bundle --entry-file=index.js --bundle-output=./ios/main.jsbundle --dev=false --platform=ios"

**➜ Move git:(dev) ✗ npm run build:ios

Move@0.0.1 build:ios /Users/user/Documents/React_Native/Move
react-native bundle --entry-file=index.js --bundle-output=./ios/main.jsbundle --dev=false --platform=ios

             Welcome to React Native!
            Learn once, write anywhere

info Writing bundle output to:, ./ios/main.jsbundle
info Done writing bundle output
warn Assets destination folder is not set, skipping...**

Images are not loading in release mode.

Thanks in advance.

@Osamasomy
Copy link

我只想知道为什么明明需要main.jsbundle文件,框架却不自动生成。。。。。

TRANSLATE INTO ENGLISH

I just want to know why the main.jsbundle file is obviously needed, but the framework is not automatically generated

@robertoclavijob
Copy link

  "scripts": {
    ...
    "bundle:ios": "react-native bundle   --entry-file   index.js  --bundle-output ios/bundle/index.jsbundle   --dev  false  --platform ios  --assets-dest  ios",
    "postinstall": "npm run bundle:ios"
  }

change yourself jsbundle file name

This was the only way to get it working on AppCenter. Thanks @foxundermoon

@peterharding
Copy link

peterharding commented Jun 7, 2021

During an upgrade from 0.61 to 0.62, I encountered a strange state where the packager would start, but would not create the bundle. None of the normal solutions worked for me, and it turns out I had a strange line in my project.pbxproj file:

"GCC_PREPROCESSOR_DEFINITIONS[arch=*]" = "FB_SONARKIT_ENABLED=1";

Removing this line solved the issue, hopefully this helps someone else save 3 days worth of effort 😓

@SanjanaTailor
Copy link

@shinriyo run this command inside project:
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

Thanks a lot this worked for me

@felixolivares
Copy link

@shinriyo run this command inside project: react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

Worked for me as well! Thanks

@Dsantacruz
Copy link

@shinriyo run this command inside project: react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

Worked for me as well! Thanks

This worked for me

@DmitryBD
Copy link

DmitryBD commented Jan 9, 2022

I was able to fix the bug by changing the project.pbxproj "Build Phases -> Bundle React Native code and images" to

export NODE_BINARY=node

# The project root by default is one level up from the ios directory
export PROJECT_ROOT="$PROJECT_DIR"/..

`node --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"`

This way all the js bundle and assets will be added while building the code projects. Works with react-native >= 0.63

@mandotleung-zensis
Copy link

For my case,

  • react-native 0.65.1
  • use nvm manage the node
  • xcode 13
  • non M1 mac
  • MacOS 12.1
    It is found that the shell script issue cause the jsbundle do not generate correctly but the xcode archive task still success.

Change the script in "Build Phases -> Bundle React Native code and images" as below work for me.

export RN_DIR="$PROJECT_DIR/../node_modules/react-native" && pwd
export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh

@chellongCoder
Copy link

My problem is I've install node with fishshell I've change the Bundle React Native code and image on Build Phases to:

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

then run react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios' now actually I have images on real device.

your save my day 🎁

@shayelbaz1
Copy link

My problem is I've install node with fishshell I've change the Bundle React Native code and image on Build Phases to:

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

then run react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios' now actually I have images on real device.

image

@kennydifiore
Copy link

@shayelbaz1 We had a similar problem when using Node Version Manager (nvm). If your "default" node installation alias isn't set to the version of node you're using for the RN builds, then it will result in error. If the build script from react-native included a step to detect if NVM was being used and then call nvm use from the main project folder, that would alleviate problems that NVM users have. The workaround for us was to change the "default" node installation alias in NVM to the one used by our react-native builds.

@matthewwo
Copy link

@shayelbaz1 We had a similar problem when using Node Version Manager (nvm). If your "default" node installation alias isn't set to the version of node you're using for the RN builds, then it will result in error. If the build script from react-native included a step to detect if NVM was being used and then call nvm use from the main project folder, that would alleviate problems that NVM users have. The workaround for us was to change the "default" node installation alias in NVM to the one used by our react-native builds.

Indeed was caused by nvm in my case as well. I've removed .nvm from my home directory and a few lines in .zshrc and fixed it instead.

@matthewwo
Copy link

matthewwo commented Jun 15, 2022

In my opinion this could have been caught earlier during the Bundle React Native code and images phase and throw a compile error instead of letting it continue until the app launches and crashes.

Maybe inside the react-native-xcode.sh script it should throw an error already when there's a node related problem?

CleanShot 2022-06-15 at 12 00 26

@mavine4512
Copy link

run this at the root of the project's terminal:
react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'

@saltict
Copy link

saltict commented Sep 17, 2022

✅ It worked for me.

Open mac settings> network> select your connection> Advanced> Proxies> Automatic Proxy Discoveries (Uncheck). Captura de Tela 2020-11-30 às 17 20 53

It saved me, I forgot to ignore localhost when config the proxy. Thank you so much!

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment 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 Mar 16, 2023
@github-actions
Copy link

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

@facebook facebook locked as resolved and limited conversation to collaborators Mar 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: iOS iOS applications. 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