facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.47k stars 24.26k forks source link

Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release. #27157

Closed FredrickNarshChiluba closed 3 months ago

FredrickNarshChiluba commented 4 years ago

React Native version:

Steps To Reproduce

1. 2.

Describe what you expected to happen:

Snack, code example, screenshot, or link to a repository:

IzabellaK2105 commented 4 years ago

The same problem on Windows 10. I tried suggestions found on web but no success.

react-native-cli: 2.0.1 react-native: 0.59.10

psaiprakash commented 4 years ago

The same problem I am facing. Upgrading node, clearing cache none of it worked

jihadrhamza commented 4 years ago

I have solved the problem using the below steps.

  1. Updated nodejs to the latest version.
  2. Deleted the all the contents from .gradle(C:/Users/xxx/.gradle) folder (You may skip this in the initial attempt)
  3. I created project using,

    react-native init MyApp

  4. Move to the project folder.

    cd MyApp

  5. I was getting some blacklist.js some character issue. For that I referred this link and replaced sharedBlacklist character set. (https://stackoverflow.com/questions/58120990/how-to-resolve-the-error-on-react-native-start/58122821#58122821)
  6. Next, I ran the below code snippet to address the bundle issue.( Ref Link : https://medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff)

    react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

  7. react-native run-android Then, it started working. Hope this helps.

dipo1 commented 4 years ago

In my case, the emulator was on airplane mode. Make sure your emulator or mobile phone can communicate with the Metro server.

cameramanbrayton commented 4 years ago

Awesome it works, finally. Thank you so much

stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

Shisso23 commented 4 years ago

I still have that problem. someone help please. my emulator is not in airplane mode

oscarcornejo commented 4 years ago

I still have that problem.

mrousavy commented 4 years ago

Also still having that problem on 0.63.2

alina-beck commented 4 years ago

I have the same issue after upgrading from react-native 0.61.5 to 0.63.2.

Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

These are the buildTypes settings in my android/app/build.gradle (working fine for previous versions of react-native):

    buildTypes {
        debug {
            resValue "string", "CodePushDeploymentKey", '""'
        }
        staging {
            resValue "string", "CodePushDeploymentKey", '"******"'
            signingConfig signingConfigs.release
            matchingFallbacks = ['release']
        }
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            resValue "string", "CodePushDeploymentKey", '"******"'
            signingConfig signingConfigs.release
        }
    }

Please help! All the "solutions" I found so far were either suggesting to start a Metro Instance, or adding an assets folder (which already exists in my project), or running a three-lines-long bundle command – but surely there must be a better way!?

Update: Adding bundleInStaging: true to my app/build.gradle as suggested in this answer solved this problem for me! :tada:

andreipfeiffer commented 3 years ago

If you are encountering this issue on Android 28+ in Debug Mode, make sure you add this to your AndroidManifest.xml:

<application
+   android:usesCleartextTraffic="true"
    ...

In my case, the app was running ok in Production Mode, but it didn't start in Debug Mode. Because of some network security issues, the app was unable to connect to the Metro bundler, even when it was running.

Source: https://reactnative.dev/docs/integration-with-existing-apps#cleartext-traffic-api-level-28

For more details & more fine grained approaches: https://github.com/facebook/react-native/issues/22375

JongLim107 commented 3 years ago

Hi everybody~

### Here is my solution

None of the above solutions can solve my problem but only follow the below steps working for me. Add in network-security-config.xml file

    <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">10.0.2.2</domain>
    </domain-config>
    ...

Then update AndroidManifest.xml file with

<application
+   android:networkSecurityConfig="@xml/network_security_config"
    ...
arashmad commented 3 years ago

I have solved the problem using the below steps.

  1. Updated nodejs to the latest version.
  2. Deleted the all the contents from .gradle(C:/Users/xxx/.gradle) folder (You may skip this in the initial attempt)
  3. I created project using,

    react-native init MyApp

  4. Move to the project folder.

    cd MyApp

  5. I was getting some blacklist.js some character issue. For that I referred this link and replaced sharedBlacklist character set. (https://stackoverflow.com/questions/58120990/how-to-resolve-the-error-on-react-native-start/58122821#58122821)
  6. Next, I ran the below code snippet to address the bundle issue.( Ref Link : https://medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff)

    react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

  7. react-native run-android Then, it started working. Hope this helps.

It worked for me by doing one extra step. I had to delete two directories.

  1. /android/.gradle
  2. /android/app/build

Then ran npx react-native run-android command.

mobihunterz commented 3 years ago

In my case, the emulator was on airplane mode. Make sure your emulator or mobile phone can communicate with the Metro server.

Thanks but same for me as well. It resolved now.

bandhavya commented 3 years ago

Im getting this error on real device. but not on emulator. I have tried few solutions mentioned above but none of them help me.

I tried executing network-security-config.xml change. It didnt help.

Then tried executing https://medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff

But nothing works for me. only installing apk, on app start it throws the error always

YouCii commented 3 years ago

For my case,i want to load assets file to replace downloading from local-server,so i modified the MainApplication to change ReactNativeHost, and the reason is that the code is wrong. When i change to this, it runs well

private final ReactNativeHost mReactNativeHost =
            new ReactNativeHost(this) {
                @Override
                public boolean getUseDeveloperSupport() {
                    return false;
                }

                @Override
                protected List<ReactPackage> getPackages() {
                    return new PackageList(this).getPackages();
                }

                @Override
                protected String getJSMainModuleName() {
                    return "index";
                }

                @Override
                protected ReactInstanceManager createReactInstanceManager() {
                    ReactMarker.logMarker(ReactMarkerConstants.BUILD_REACT_INSTANCE_MANAGER_START);
                    ReactInstanceManagerBuilder builder =
                            ReactInstanceManager.builder()
                                    .setApplication(MainApplication.this)
                                    .setJSMainModulePath(getJSMainModuleName())
                                    .setUseDeveloperSupport(getUseDeveloperSupport())
                                    .setRedBoxHandler(getRedBoxHandler())
                                    .setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
                                    .setUIImplementationProvider(getUIImplementationProvider())
                                    .setJSIModulesPackage(getJSIModulePackage())
                                    .setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
                                    .setBundleAssetName("index.android.bundle");

                    for (ReactPackage reactPackage : getPackages()) {
                        builder.addPackage(reactPackage);
                    }

                    ReactInstanceManager reactInstanceManager = builder.build();
                    ReactMarker.logMarker(ReactMarkerConstants.BUILD_REACT_INSTANCE_MANAGER_END);
                    return reactInstanceManager;
                }
            };
jeremywhittington commented 3 years ago

I was running into this same issue on Windows 10. The problem I was experiencing was I had something running on port 8081. When I stopped it, everything worked.

stale[bot] commented 2 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

airowe commented 2 years ago

Im getting this error on real device. but not on emulator. I have tried few solutions mentioned above but none of them help me.

I tried executing network-security-config.xml change. It didnt help.

Then tried executing medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff

But nothing works for me. only installing apk, on app start it throws the error always

Same thing for me. Did you ever get this working on a real device?

lekeCoder commented 2 years ago

I am having this issue in release mode

foxbit19 commented 2 years ago

Same here using npx react-native run-android --variant=release. I've used ./gradlew clean into android folder but the issue persists. No sign of this problem in debug mode. I'm using RN 0.69.3.

foxbit19 commented 2 years ago

I've solved it in this way. Hope it helps.

navin9584 commented 1 year ago

i just delete node_module and reinstall it and its work for me

coder054 commented 1 year ago

I still have that problem. someone help please. my emulator is not in airplane mode

https://www.fullstackoasis.com/articles/2022/05/30/react-native-unable-to-load-script-make-sure-youre-either-running-a-metro-server/

coder054 commented 1 year ago

https://www.fullstackoasis.com/articles/2022/05/30/react-native-unable-to-load-script-make-sure-youre-either-running-a-metro-server/

shiv-2810 commented 1 year ago

I have build the app using fastlane and when i am opening the app, bugsnag is reporting this errror,

Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

navin9584 commented 1 year ago

hi , pease try to start metro server or CLI using npm start or npx react-native start

thankyou


From: Shivam Kumar @.> Sent: Wednesday, July 12, 2023 6:23 PM To: facebook/react-native @.> Cc: Navin Nahar @.>; Comment @.> Subject: Re: [facebook/react-native] Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release. (#27157)

"External Email Notice: This email originated from outside your organisation. Please be mindful of safe email handling and open the attachments / links contained there-in only if the sender is trustworthy and known to you."

I have build the app using fastlane and when i am opening the app, bugsnag is reporting this errror,

Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

— Reply to this email directly, view it on GitHubhttps://github.com/facebook/react-native/issues/27157#issuecomment-1632476500, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AV5RMPVIL3IJ6OSRXFTGZELXP2M4VANCNFSM4JKIOYJA. You are receiving this because you commented.Message ID: @.***>

DISCLAIMER: The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to share any part of this message with any third party, without a written consent of the sender. If you received this message by mistake, please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future. DISCLAIMER: The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to share any part of this message with any third party, without a written consent of the sender. If you received this message by mistake, please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.

NicholusMuwonge commented 1 year ago

I have build the app using fastlane and when i am opening the app, bugsnag is reporting this errror,

Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

Did you resolve this, I used Fastlane as well, and I get this error in production

tpurg commented 1 year ago

I'm not sure which of these things really fixed it for me, but after 3 days of trying to figure this out here's what I changed to make it work without hacks and allowing to make hot reloading still work in dev:

Hopefully it works, this error is just so out of nowhere.

JoaoGracio107 commented 1 year ago

I'm not sure which of these things really fixed it for me, but after 3 days of trying to figure this out here's what I changed to make it work without hacks and allowing to make hot reloading still work in dev:

  • Removed node_modules, package-lock.json
  • I switched to node version 18.7.1 with nvm
  • I added android:usesCleartextTraffic="true" in AndroidManifest.xml
  • ran npm udpate
  • But what I think sealed the deal, was going to settings of my phone and deleting the apps cache and data Hopefully it works, this error is just so out of nowhere.

Where in your project is AndroidManifest.xml can't seem to find it on mine?

tpurg commented 1 year ago

Where in your project is AndroidManifest.xml can't seem to find it on mine?

The file is in android/app/src/main

kxngdavid commented 9 months ago

hi , pease try to start metro server or CLI using npm start or npx react-native start thankyou ____ From: Shivam Kumar @.> Sent: Wednesday, July 12, 2023 6:23 PM To: facebook/react-native @.> Cc: Navin Nahar @.>; Comment @.> Subject: Re: [facebook/react-native] Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release. (#27157) "External Email Notice: This email originated from outside your organisation. Please be mindful of safe email handling and open the attachments / links contained there-in only if the sender is trustworthy and known to you." I have build the app using fastlane and when i am opening the app, bugsnag is reporting this errror, Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release. — Reply to this email directly, view it on GitHub<#27157 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AV5RMPVIL3IJ6OSRXFTGZELXP2M4VANCNFSM4JKIOYJA. You are receiving this because you commented.Message ID: @.***> DISCLAIMER: The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to share any part of this message with any third party, without a written consent of the sender. If you received this message by mistake, please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future. DISCLAIMER: The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to share any part of this message with any third party, without a written consent of the sender. If you received this message by mistake, please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.

This worked perfectly for me. apparently i was trying to install the app on my physical device but hadn't yet started by running this command.

Nb: If you try to run the command above (npx react-native start) and you get an error concering the port 8081 already in use, kill the processes on the port by running very simple commands. i used chatgpt for this (just lookup how to kill running processes on port 8081 for eg windows) . And try again

Best!

github-actions[bot] commented 3 months ago

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[bot] commented 3 months ago

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

gilons commented 1 month ago

Nice, Had to connect the Emulator to Android WIFI. It's a weird issue.

diegoleondev commented 1 month ago

In my case, the emulator was on airplane mode. Make sure your emulator or mobile phone can communicate with the Metro server.

That was my mistake, thanks @dipo1