Expo with WSL2 over lan

I recently started using expo with WSL2, and want to connect a physical device to expo. The tunnel option works, but is slow and impossible to use with a debugger. I’d like to be able to connect directly with a device on the same wifi network.

There are some problems with the networking configuration in WSL2, but I’ve been able to overcome them when using a python webserver. If I do the following:

(On windows)
netsh interface portproxy add v4tov4 listenport=19000 listenaddress=0.0.0.0 connectport=19000 connectaddress=127.0.0.1
netsh advfirewall firewall add rule name="TCP Port Open" dir=in action=allow protocol=TCP localport=19000

(on ubuntu)
python3 -m http.server 19000

Then I am able to access the following:
localhost:19000
192.168.1.3:19000 (windows ip, from same machine)
192.168.1.3:19000 (from external device on same lan network)

However, when I run expo start I can only access from localhost. Now, I noticed that expo by default binds to the local WSL ip, while the python command binds to 0.0.0.0

So I tried export env REACT_NATIVE_PACKAGER_HOSTNAME=0.0.0.0
Now, expo starts on the same ip and port as the python command, but I am still unable to connect to expo. Is there something I’m missing in how it binds to the address?

One thing I noticed is ss -tulw prints
(expo)

Netid           State             Recv-Q            Send-Q                         Local Address:Port                          Peer Address:Port
tcp             LISTEN            0                 128                                        *:19000                                    *:*

(python)

Netid           State             Recv-Q            Send-Q                         Local Address:Port                          Peer Address:Port
tcp             LISTEN            0                 5                                    0.0.0.0:19000                              0.0.0.0:*

I’d really like to get expo working smoothly with WSL2 so that I can debug properly, so if anyone has suggestions I’d greatly appreciate it!

  Expo CLI 3.21.5 environment info:
    System:
      OS: Linux 4.19 Ubuntu 18.04.4 LTS (Bionic Beaver)
      Shell: 4.4.20 - /bin/bash
    Binaries:
      Node: 14.3.0 - ~/.nvm/versions/node/v14.3.0/bin/node
      Yarn: 1.12.3 - /usr/bin/yarn
      npm: 6.14.5 - ~/.nvm/versions/node/v14.3.0/bin/npm
    npmPackages:
      expo: ^37.0.12 => 37.0.12
      react: 16.9.0 => 16.9.0
      react-dom: 16.9.0 => 16.9.0
      react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4
      react-native-web: ~0.11.7 => 0.11.7
      react-navigation: ^4.3.9 => 4.3.9
    npmGlobalPackages:
      expo-cli: 3.21.5
1 Like

I have the same issue. First of all, make sure you do the same for port 19001 on Windows, as it is used by the Metro bundler. I have both forwarded and added to firewall exceptions, I can access both from anywhere on my local network, including from the phone where the Expo app is installed - I can load both in its browser. However, the app simply fails to open. When I run Expo on my Mac machine the app connects just fine.

I’m having the same problem. I start expo on my linux distro, inside WSL… and I receive as IP something like exp://172.27.226.58:19000 to LAN mode

But when try access it from my smarthphone, nothing happens.

Its a problem, because, work over tunnel its slow

I FOUND THE SOLUTION

FOR THOSO WHO WANT TO ACCESS THE EXPO INSIDE LAN WITH WSL, FOLLOW THE STEPS INSIDE