npx react-native start in your project root to avoid this error! I’m using Ubuntu 21.04 and Android. YMMV.
The React Native project has great documentation to help you get started creating a new project. Just follow the instructions there, and you’ll be gold.
However, when you follow those steps, you will use the React Native CLI (command line interface) to create a new project, like so:
npx react-native init AwesomeProject
That’s just what they tell you to do in the documentation. After doing that, the CLI helpfully informs you to
cd "/home/user/AwesomeProject" && npx react-native run-android. At this point, someone might actually follow these instructions (imagine that!) instead of continuing to follow the instructions on the webpage I linked to above. If they do, they will be met with the red screen of death, which reads “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.”
This is still happening in 2022, and I wrote about it in 2020.
In those olden days, I figured out that I had to run
npm start in a terminal window in order to get Metro server running before running
npx react-native run-android. Then, in a separate window, I needed to run
npx react-native run-android, which would load the app onto my device.
More recently, I try to stick with
npx entirely. So I open two terminals. In one, I run
npx react-native start, and in the other, I run
npx react-native run-android. That’s it! It surprises me that the CLI still hasn’t been updated to correct the instructions that skip the part about getting Metro server running. This is just a PSA for anyone who might still be led astray by the “helpful” CLI prompt.