Kirti Parghi
Kirti Parghi

Reputation: 1152

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!!!

Upvotes: 7

Views: 15378

Answers (2)

suther
suther

Reputation: 13578

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.

Upvotes: 6

Im Batman
Im Batman

Reputation: 1876

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

Upvotes: 7

Related Questions