React Native & Expo Go : Network response timed out

56 Views Asked by At

I'm new to React Native (but not React) and I wanted to follow the guide in the documentation : https://reactnative.dev/docs/environment-setup

The create-expo-app is working just fine, but when I try to start the App, everything seems fine in the console except ExpoGo App is showing "Something went wrong. Network response timed out" when I scan the QR Code. Same when I type the URL manually.

Do you know where this can come from ?

I'm on Windows but I'm using the Ubuntu terminal (WSL), and both my devices are on the same Wi-Fi.

1

There are 1 best solutions below

0
Keith Russo On

When I was setting up my RN dev environment using Windows to house Android Studio for my emulators but keeping all my code on WSL2, I had a rough time getting everything setup as well. It sounds like you most likely don't have your port 8081 forwarded from WSL2 to Windows.

This all assumes that you have Node >=18 (I use 20) and Java (I use 17 for RN 0.73) installed on WSL and Android Studio installed on Windows

I use the command line (Admin Powershell) to do the Windows side of things.

  • Port forward 8081 so metro/expo can talk to your emulator
iex "netsh interface portproxy delete v4tov4 listenport=8081 listenaddress=127.
0.0.1" | out-null;
$WSL_CLIENT = bash.exe -c "ifconfig eth0 | grep 'inet '";
$WSL_CLIENT -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
$WSL_CLIENT = $matches[0];
iex "netsh interface portproxy add v4tov4 listenport=8081 listenaddress=127.0.0.1
connectport=8081 connectaddress=$WSL_CLIENT"
  • Start your emulator.

This command should hold the process in the terminal window

cd c:\path\to\Android\Sdk\emulator && .\emulator.exe -avd <name-of-your-avd>
  • Your Virtual Device should startup

  • Open a new terminal window and start the ADB server

This command should hold the process in the terminal window

adb kill-server && adb -a nodaemon server start

If this command gives an error, just CD into the Android SDK folder that contains the ADB executable or setup adb in your PATH

  • In WSL, you also have to kill the server, but need to run another command.
adb kill-server && socat -d -d TCP-LISTEN:5037,reuseaddr,fork TCP:$(cat /etc/resolv.conf | tail -n1 | cut -d " " -f 2):5037

You may have to install socat if you don't already have it installed

This should be all you need to do extra to get your RN project talking between WSL and Windows.

A guide that I found very helpful for working through networking issues during my setup can be found here.

Also, if you are behind a proxy, there are several points throughout the setup where you will need to add your proxy information so you can reach the outside. So that's another networking piece to consider.

It may not be the perfect solution for everyone depending on our exact setup, but this is what I was able to use to get myself and other coworkers with working dev environments with Windows & WSL2.

Hope this helps.

UPDATE: One thing I failed to consider in my original post is that you are testing on physical devices. Depending on your exact setup, you may need to expose additional ports and install additional libraries on WSL2.