Yethin Dias
Yethin Dias

Reputation: 1

Could not connect to development server. Error while running

I have tried to restart the server with npm start, npx react-native run-ios, npx react-native start. Those commands don't work for me. Help me out to run this project its a project created with npx react native init projectName.

warn No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.

The error shown on the emulator

Upvotes: 0

Views: 6351

Answers (3)

Akrem Gomri
Akrem Gomri

Reputation: 23

I had the same problem and spent hours working on it. I figured out that METRO which is run using this command: npm start or this one npx react-native start couldn't find its way to my mobile app.

one of the solutions that I wasn't totally pleased of was this: a solution that works but has flows

but that workaround wasn't perfect because I had to re-run the command every single time I make a change. So after further researches I found out that the port 8081 is used by an another application that METRO is sending information to ( this is only my guess ). so:

  1. I run the following:

    netstat -aon | findstr 8081 // to get the PID of the application that is running on 8081 port

  2. I opened task manager ( CRTL + ALT + del ) under the service section I looked up any application which uses the PID that matches the one given by the command I ran and I have forced stopping it.

  3. retried npx react-native start and npx react-native run-android on my project

and the magic happened. It auto refreshes with every change, I wish it helps you.

Upvotes: 1

Taoufik
Taoufik

Reputation: 664

This is from the docs:

Method 2: Connect via Wi-Fi

You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.

Open a terminal and type /sbin/ifconfig to find your machine's IP address.

  1. Make sure your laptop and your phone are on the same Wi-Fi network.
  2. Open your React Native app on your device.
  3. You'll see a red screen with an error. This is OK. The following steps will fix that.
  4. Open the in-app Developer menu.
  5. Go to Dev Settings → Debug server host for device.
  6. Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
  7. Go back to the Developer menu and select Reload JS

Upvotes: 0

Ridwan Ajibola
Ridwan Ajibola

Reputation: 1059

Run adb reverse tcp:8081 tcp:8081 in your terminal then reload in the terminal after running yarn start or npm start, then reload. I hope this is helpful.

Upvotes: 1

Related Questions