Search code examples
windows-subsystem-for-linux

Unable to connect to Expo React Native Project on WSL2 with Expo Go on phone


So i have just recently migrated to WSL2. And all the tools I used on WSL1 are now broken.

Commands like:

$ expo start
$ npm start

are running the app on the IP Address 172.--.---.---
This breaks many of the tools I Use that still run on 192.---.--.-

For example, when I try to connect to my Expo React Native Project with Expo go. It throws me the error:-

errorImage

The above picture is not accurate to the error I am getting. But as it is shown, I cannot access Expo Projects with a Port Other than that is configured on my phone.

Is there a way to change my WSL2 subsystem's IP to my host machine's so that I can connect to my Expo project from my phone?


Solution

  • You can use a tunnel with Expo (docs are here).

    npm start -- --tunnel
    

    This will ask to install the @expo/ngrok package. Once that is done, you'll see the Metro is waiting message has a full URL instead of just an IP address.

    Scan the QR code and Expo Go will connect through the tunnel.

    This works because the tunnel is exposed to the internet, instead of just your local network.