Search code examples
react-nativevpnexpoexpo-web

How To Have Expo Web Open In A Web Browser With Localhost?


Running npm start or expo start launches the project as follows:

React  You can now view My React Native App in the browser.

  Local:            http://localhost:19006/   On Your Network:  http://157.201.29.49:19006/

Note that the development build is not optimized.

 › To create a production build, run expo build:web  › Press Ctrl+C to exit.

 Expo  Press ? to show a list of all available commands.

Launching the Expo web by pressing ‘w’ opens Chrome browser with the IP address URI http://157.201.29.49:19006/ as advised.

However because of the office VPN, Chrome browser fails to resolve the address. The error is:

This site can’t be reached
ERR_CONNECTION_TIMED_OUT

Replacing the URL in Chrome with http://localhost:19006 succeeds.

How can I start Expo such that pressing ‘w’ automatically launches with localhost rather than the IP address?


Solution

  • To fix, launch expo directly as follows supplying the localhost option:

    expo start —-localhost
    

    See Expo CLI docs for expo start:

    --localhost Same as --host localhost