create-react-native-app: Can't make requests to local API server

Description

Can’t connect to an API server ran on my local machine from my android phone running my Expo app. The IP address of my machine on my local network is 192.168.1.14, so my app is served on the URL http://192.168.1.14:19000. My API server is on http://192.168.1.14:3000, and I can connect to it on my phone browser.

Expected Behavior

The fetch request to http://192.168.1.14:3000 should return the same data as the request through my browser.

Observed Behavior

I have to wait around 30 seconds of awaiting for a response, then I get this:

Possible Unhandled Promise Rejection (id: 0):
TypeError: Network request failed
onerror@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:13802:29
dispatchEvent@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:14702:39
setReadyState@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:16809:31
__didCompleteResponse@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:16665:27
http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:16760:50
emit@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:5278:40
__callFunction@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:3517:47
http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:3375:29
__guard@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:3489:11
callFunctionReturnFlushedQueue@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:3374:19
callFunctionReturnFlushedQueue@[native code]

Environment

Please run these commands in the project folder and fill in their results:

  • npm ls react-native-scripts: react-native-scripts@0.0.30
  • npm ls react-native: react-native@0.44.2
  • npm ls expo: expo@17.0.0
  • node -v: v7.4.0
  • npm -v: 4.0.5
  • yarn --version: 0.24.5
  • watchman version: 4.7.0

Also specify:

  1. Operating system: Ubuntu 16.04
  2. Phone/emulator/simulator & version: Android 6.0.1

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

hello! I think you may be mistaken and have made some error somewhere in your code. see https://github.com/brentvatne/crna-issue-241-example for a minimal example of what you describe in this issue, and notice that it works as expected. if that example doesn’t work for you then let me know!

Hi. I had the same problem and i can connect the mobile app with react native to the asp.net server web app. I have to turn off the firewall of windows, that was blocked my ports and i wasnt able to connect to the server api. This work for me.

you need to be able to access the server from your phone. if you can’t access it from a web browser you also can’t access it from an app