Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find variable: _d when running react native app for the first time

I just created react native app using react-native init demoone and started js server using react-native start then trying to execute the app with react-native run-android But i am getting the following error in emulator when it is installed.

can't find variable: _d(http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:1)

enter image description here

like image 529
Chandra Kiran Avatar asked Dec 20 '17 13:12

Chandra Kiran


People also ask

How do you run on IOS device react native?

Open your react native app's directory, navigate to ios folder, and double-click on . xcworkspace file to open the Xcode. Next, open the Product menu, go to Destination, and select your device. If you don't have an Apple Developer account, you must create one to be able to run your project on an iOS device.


Video Answer


2 Answers

I faced the same problem, while trying to set up the react-native env in Win10 and attempting to run Sample Project.

After hours of banging my head and scrolling through site found the solution in here!

The problem is, when you run react-native run-android from the project root folder, it automatically starts a default instance of node-js packager server at the port 8081. For some reason it doesn't let the hot/live/ or even manual reloading work & throws the same non-descriptive error.

Solution is to stop all running instances of the app & to run:

    yarn start
    // or
    npm start

from the root folder to create your own bundler server manually. Prefer npm or yarn over react-native start (Worked for me)

And then execute

    react-native run-android

using another cmd window to run the application on the emulator.

So the idea is to create a separate bundler everytime to run the application.

Works like a Charm!

like image 149
arjnt Avatar answered Oct 04 '22 20:10

arjnt


You need run this command to fix it:

adb reverse tcp:8081 tcp:8081

This sets up a reverse proxy between your emulator/device to your port 8081. Just make sure your emulator and react native bundler(react-native start) are running before you run this command. Another thing I came across specific to android emulator, set your debug server host to localhost:8081 from Dev settings in your app, otherwise it doesn't connects to remote debugger.

like image 42
Fawaz Avatar answered Oct 04 '22 20:10

Fawaz