Connect Phone to Expo Running in WSL2: Step-by-Step Guide
In this article
To connect your phone to Expo running in WSL2, you need to make the Metro bundler reachable from your phone over the local network. The most reliable method is to run Expo in tunnel mode with npx expo start --tunnel, which routes traffic through Expo's servers and bypasses WSL2's network isolation. Alternatively, you can set up port forwarding from Windows to WSL2 and use your Windows host IP. This guide walks through both approaches, plus common pitfalls and fixes.
What You'll Need
- A Windows PC with WSL2 installed and a Linux distribution (Ubuntu recommended).
- Node.js and npm installed inside your WSL2 environment.
- The Expo Go app installed on your phone (from the official App Store or Google Play Store).
- Your phone and Windows PC connected to the same Wi-Fi network (for LAN mode) or an internet connection (for tunnel mode).
- Basic familiarity with the WSL2 terminal and Windows PowerShell (or Command Prompt).
Step-by-Step
- Install Node.js and Expo CLI in WSL2. Open your WSL2 terminal and run
node -vto check if Node.js is installed. If not, install it using your distribution's package manager or Node Version Manager (nvm). Then install Expo CLI globally withnpm install -g expo-cli(or usenpx expowithout global install). - Create or navigate to your Expo project. If you don't have a project yet, run
npx create-expo-app my-appand thencd my-app. Otherwise, open your existing project folder in the WSL2 terminal. - Start the Expo development server in tunnel mode. Run
npx expo start --tunnel. This uses ngrok to create a public URL that your phone can reach, bypassing WSL2's NAT. Wait for the QR code to appear in the terminal. - Scan the QR code with Expo Go. On Android, open Expo Go and use the built-in QR scanner. On iOS, use the Camera app to scan the QR code; it will prompt you to open Expo Go. Ensure your phone has an internet connection.
- If tunnel mode is slow or fails, try LAN mode with port forwarding. First, find your Windows host IP address by running
ipconfigin Windows PowerShell and noting the IPv4 address of your active Wi-Fi or Ethernet adapter (e.g., 192.168.1.100). Then, in WSL2, start Expo withnpx expo start --lan. Note the port number (usually 8081). - Set up port forwarding from Windows to WSL2. Open PowerShell as Administrator and run:
netsh interface portproxy add v4tov4 listenport=8081 listenaddress=0.0.0.0 connectport=8081 connectaddress=$(wsl hostname -I). Replace8081with your Expo port if different. Also allow the port through Windows Firewall:New-NetFirewallRule -DisplayName "Expo Metro" -Direction Inbound -LocalPort 8081 -Protocol TCP -Action Allow. - Connect your phone using the LAN URL. In the Expo terminal, you'll see a URL like
exp://192.168.1.100:8081. Open Expo Go on your phone, tap "Enter URL manually" (or similar), and type that URL. Alternatively, scan the QR code if it shows the LAN IP. - Verify the connection. Your phone should load the JavaScript bundle and display your app. If it doesn't, check the troubleshooting section below.
Common Mistakes
- Using localhost in the URL. WSL2 has its own network namespace, so
localhostfrom your phone won't reach the Expo server. Always use your Windows host IP or tunnel mode. - Forgetting to allow the port through Windows Firewall. Even with port forwarding, Windows Firewall may block incoming connections. The firewall rule above is essential.
- Running Expo in LAN mode without port forwarding. By default, WSL2's network is NAT'd, so your phone cannot reach the WSL2 IP directly. Port forwarding is required.
- Using the wrong IP address. If you have multiple network adapters (e.g., VPN, Ethernet, Wi-Fi), pick the one that your phone can reach. Disable VPNs temporarily if needed.
- Not restarting the Expo server after changing network settings. Changes to port forwarding or firewall may require restarting Expo.
Tips
- Use tunnel mode for the quickest setup, but be aware it can be slower than LAN mode due to the extra hop through ngrok.
- For LAN mode, ensure your phone and PC are on the same subnet. Guest Wi-Fi networks often isolate devices.
- You can make port forwarding persistent by adding the
netshcommand to a startup script, but remember to update it if your WSL2 IP changes (it can change after reboots). - Use
npx expo start --tunnelwith a clean cache if you encounter connection issues:npx expo start --tunnel -c. - Keep Expo CLI and Expo Go updated to the latest versions for best compatibility.
Troubleshooting
If your phone cannot connect, work through these checks in order:
- Check that Expo is running and the QR code is visible. If the terminal shows errors, fix them first.
- Verify network connectivity. On your phone, open a browser and try to reach your Windows host IP (e.g.,
http://192.168.1.100:8081). If it times out, the port forwarding or firewall is likely the issue. - Confirm port forwarding is active. In PowerShell, run
netsh interface portproxy show allto list rules. Ensure the listen address is0.0.0.0and the connect address is your WSL2 IP. - Check Windows Firewall. Temporarily disable the firewall (not recommended for long-term) to see if it's blocking. If so, re-enable it and add the specific rule.
- Restart WSL2 and Expo. Sometimes network changes require a restart. Close the Expo terminal, run
wsl --shutdownin PowerShell, reopen WSL2, and start Expo again. - Try tunnel mode as a fallback. If LAN mode fails, tunnel mode usually works because it doesn't rely on local network configuration.
- Check for VPN or proxy interference. Disable VPNs on both Windows and phone, and ensure no proxy is set that blocks local traffic.
If none of these work, consult the Expo documentation or community forums for WSL2-specific issues.
Frequently Asked Questions
Why can't my phone reach the Expo server running in WSL2?
WSL2 uses a virtual network with NAT, so the WSL2 IP is not directly accessible from your phone. You need port forwarding on Windows or tunnel mode.
Do I need to use tunnel mode?
No, but it's the simplest method. LAN mode with port forwarding works and is faster, but requires more setup.
Can I use Expo Go with WSL2 on a Mac?
WSL2 is Windows-only. On macOS, Expo runs natively and your phone can connect via LAN without extra configuration.
Why does the QR code show a localhost URL?
Expo may default to localhost if it can't detect a network interface. Use --lan or --tunnel flags to force a reachable URL.
Is port forwarding secure?
Port forwarding exposes the port to your local network. Ensure your network is trusted and consider using tunnel mode for added security.
What if my WSL2 IP changes after reboot?
You'll need to update the port forwarding rule. Consider scripting it or using a tool like wslhost to automate.