Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native iOS: Could not connect to development server

I have an issue while debug my app which is build by react native. Whenever i started to build, it gives me error that could not connect to development server. I tried various solutions like upgrading npm, clearing watchman cache, restarting npm. None of them is working. Any help is most welcome!!!

like image 586
Kirti Parghi Avatar asked Nov 21 '18 17:11

Kirti Parghi


People also ask

Can't connect to development server React native IOS real device?

Try this. Open another terminal and run, react-native start — reset-cache. Then run, react-native run-android on your current terminal.

Can't connect to development server ensure the following?

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.

What is Metro react native?

Metro is a development platform for React Native. This project acts as a JavaScript bundler; it manages assets, caches builds and performs hot module reloading. Metro focuses on improving the developer experience for the React Native community.


2 Answers

I know Answer is late. but this works for me everytime.

# Clean cache
rm -rf $TMPDIR/react-*; rm -rf $TMPDIR/haste-*; rm -rf $TMPDIR/metro-*; watchman watch-del-all

# Open a new tab and Start Metro Bundler directly from the project folder
react-native start  --reset-cache

# Now run `react-native run-android` or `react-native run-ios`

Original Link

like image 101
Im Batman Avatar answered Oct 18 '22 20:10

Im Batman


I've got the same issue today (out of the blue). Works like a charm before, but then it doesn't work anymore after I've upgraded react-native to from 0.58.8 to 0.60.5.

I figured out, that I got two network-devices with different IP addresses, if I type ifconfig into the Terminal: en0 with an 192.xxx address, and en1 with an 162.xxx Address.

The error at my device show, that it try to connect to the 162.-Address.

After all, I've solved it with a change in AppDelegate.mlike that:

  // Workaround for local IP:
  return [NSURL URLWithString:@"http://192.168.178.62:8081/index.bundle?platform=ios"];
  // return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

Choose your own IP for the http-Address and give it a try. To check, if you can access the Packager-URL, you also can give it a try in your Browser.

like image 28
suther Avatar answered Oct 18 '22 20:10

suther