Sunday, January 27, 2019

Solve Could not connect to development server Error in React Native

React Native runs on backhand server which starts when we apply the react-native run-android or react-native run-ios command on our command prompt screen. This command start will build up our Gradle project and start synchronizing the whole package using JS server. So when we close the server window this development server Error occurs.
When you run the android project, then you will see "Could not connect to development server" error message in your android application.

Solve Could not connect to development server Error in React Native

The message with this error should look below :-

Error Message :
Could not connect to development server.

Try the following to fix the issue :

  • Ensure the packager server is running.
  • Ensure your device/ emulator is connected to your machine and has USB debugging enabled – run ‘adb devices’ to see a list of connected devices.
  • Ensure airplane mode is disabled.
  • If you’re on a physical device connected to the machine , run ‘adb reverse tcp:8081’ to forward request from your device.
  • If your device is on the same Wi-Fi network, Set ‘Debug server host & Port for device’ in ‘Dev settings’ to your machine IP address and the port of your local Dev server – e.g. 10.0.1.1:8081.

How to Solve Could not connect to development server Error in React Native :

Step 1 : Cancel the current process of "react-native run-android" by CTRL + C or CMD + C.

Step 2 :Close metro bundler window command line which opened automatically.

Step 3 :Run the command again, "react-native run-android".
Command to use : 
react-native run-android

Step 4 : Type "react-native start" command in separate command prompt. Refer below screenshot :

Solve Could not connect to development server Error in React Native

Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.

3 comments:

  1. this is not working this is absolutely wrong

    ReplyDelete
    Replies
    1. Share your complete issue details and logs file, we will check and let you know about your issue resolution.

      Delete
  2. Wrong solution. `react-native android` will automatically open `Metro bundler on port 8081`, no need to run `react-native start`. This is not a solution.`react-native start` just starts dev server, while issue is Emulator or real device is not connecting to Dev server even if there are running.

    ReplyDelete