Amila Eranda
Amila Eranda

Reputation: 105

React Native failed to compile giving Error on the Device

I'm new to the React Native application development. When I after creating project and configured my device, It gives error like below and stop responding.

BUILD SUCCESSFUL in 27s
26 actionable tasks: 1 executed, 25 up-to-date
'C:\Users\Amila' is not recognized as an internal or external command,
operable program or batch file.
info Starting the app (C:\Users\Amila Eranda\AppData\Local\Android
\Sdk/platform-tools/adb shell am start -n 
com.awesomeproject/com.awesomeproject.MainActivity...
Starting: Intent { cmp=com.awesomeproject/.MainActivity }

It shows build is success but there is an error on the Device saying

Unable to load script. Make sure you're either running a metro server...

running the adb devices command shows there is a device connected to my PC. But it fails running it in the Device.

Upvotes: 4

Views: 763

Answers (1)

Raymond Mutyaba
Raymond Mutyaba

Reputation: 950

That error on your device means that your device cannot connect to the metro server running on your computer to get the js bundle. The app on your device is a temporary app used by react native to quickly download the javascript code from your computer and convert it to code your device can understand each and every time you make changes to your code. Your device must be connected to your computer either on the same wifi network (with metro bundler running in a terminal window on your computer) or through a usb cable (with usb debugging enabled on your device and adb reverse set on a command prompt on your computer).

Read this from the android documentation to find out how to enable developer options on your android device: https://developer.android.com/studio/debug/dev-options

If your android device lets you, you can create a hotspot and have your computer connect to it if you do not have wifi available and usb debugging does not work for you.

Read this from the react native documentation: https://facebook.github.io/react-native/docs/running-on-device#connecting-to-the-development-server-1

Upvotes: 1

Related Questions