40

I've got virtual box installed. And when I look at the host > LAN > ip address is exp://192.168.56.1:19000.

How can I change it without disable the network? because it's my virtualbox ip and my device can't connect to it.

Thanks

15 Answers 15

50

You can specify the REACT_NATIVE_PACKAGER_HOSTNAME environment variable to use the correct IP address.

If you're using XDE, then make sure to launch it from your project directory with xde . after you've installed the command line tools.

7
  • 3
    Hi, I've tried set it using cmd set REACT_NATIVE_PACKAGER_HOSTNAME='192.168.1.2' but on my expo still showing 192.168.56.1 ip address. already tried restart the expo project.
    – ssuhat
    Commented May 3, 2017 at 5:47
  • 7
    Worked for me. I just used export env REACT_NATIVE_PACKAGER_HOSTNAME=192.168.2.108 and got the desired result of having the expo on this ip after npm start.
    – Moreno
    Commented Sep 3, 2017 at 7:16
  • 2
    On Windows, it should be set REACT_NATIVE_PACKAGER_HOSTNAME=192.168.0.105
    – Felix
    Commented Oct 12, 2017 at 13:23
  • 7
    With powershell, $env:REACT_NATIVE_PACKAGER_HOSTNAME = "10.1.1.175"
    – Leo Lee
    Commented Jun 20, 2018 at 1:45
  • Works well, set REACT_NATIVE_PACKAGER_HOSTNAME with ip, and re open cmd(power shell).
    – Winner
    Commented Mar 22, 2019 at 14:09
15

In windows you can use:

set REACT_NATIVE_PACKAGER_HOSTNAME=192.168.1.59

set is only used for one session. If you always wanna use the same ip after reboot you can use:

setx /M REACT_NATIVE_PACKAGER_HOSTNAME 192.168.1.59
3
  • access to the path denied Commented Jun 11, 2022 at 23:58
  • @NewUser134, run the command shell as an administrator to resolve the access denied error
    – HBCondo
    Commented May 30, 2023 at 5:42
  • How can I run this on M1 Mac? What would be the command for the same? Commented Jun 29 at 12:16
7

Even after you set the custom ip, you still cannot connect the virtual box.

You need to set a port forward for the virtual mechine at networking setting page.

Just use the real host mechine ip for the app Expo.

 REACT_NATIVE_PACKAGER_HOSTNAME='real host mechine ip' npm start
3

check your pc whether install virtualbox , disable VirtualBox Host-Only Network

go to win pc: Control Panel\Network and Internet\Network Connections

run again command expo start is ok

2
  • Hello and welcome to Stack Overflow :) Can you please explain the detailled steps for that please? Eventually with screenshots... Thanks!
    – benichka
    Commented Nov 2, 2018 at 15:58
  • indeed that works, the problem is when you have multiple adapters aside from virtualbox, for example another wifi card, in order to work you would have to disable it too Commented Dec 13, 2018 at 21:34
3

On the Windows Subsystem for Linux (Ubuntu 18.04.1 LTS "Bionic"), I had to use the export command:

export REACT_NATIVE_PACKAGER_HOSTNAME=192.168.1.76.

2

Open CMD from your Project Directory and Run Command as set REACT_NATIVE_PACKAGER_HOSTNAME=192.168.0.12. Replace the ip with your own LAN ip address. The Command set is used to set the Environment variable locally, without defining it into Environment Variables.

1

I have similar kind of problem (with may a slight difference), but the solution doesn't work for me. Finally I tried Expo CLI tool which worked great for me and is also recommended by Expo team.

My detailed question (may help someone to resolve similar problem):

Expo LAN configuration doesn't work for New ReactNative Project

0

If you have "ubuntu in windows" configured you can automate the process and run:

for /F "usebackq delims=" %A in (`ipconfig  ^| grep -A4 'Wireless LAN adapter WiFi' ^| tail -1 ^| awk '{print $NF}'`) do set REACT_NATIVE_PACKAGER_HOSTNAME=%A
0

My problem solved by reinstall expo client on ios simulator.
I was used expo v37 before but got this problem on v38, the problem was expo client not have expo sdk 38.

0
0

Sharing my experience using EXPO with Cloud 9 and AWS Amplify. Similar with you, the QR code gives exp://localhost:19000

As the Security Group has been configured to provide public access, I regenerate the QR code to have it accessible from public IP address of exp://X.X.X.X:19000, this can be scanned from IOS devices to EXPO.

0

REACT_NATIVE_PACKAGER_HOSTNAME environment variable is ment for react DevTools. For EXPO, you have to set EXPO_DEVTOOLS_LISTEN_ADDRESS environment variable. Here is the weird function that determines the hostname :

function devtoolsGraphQLHost() {
    if (process.env.EXPO_DEVTOOLS_LISTEN_ADDRESS && process.env.REACT_NATIVE_PACKAGER_HOSTNAME) {
        return process.env.REACT_NATIVE_PACKAGER_HOSTNAME.trim();
    }
    else if (process.env.EXPO_DEVTOOLS_LISTEN_ADDRESS) {
        return process.env.EXPO_DEVTOOLS_LISTEN_ADDRESS;
    }
    return 'localhost';
}
0

If you're still having this problem, try switching to tunnel connection. It'll install @expo/ngrok@ and then you can scan the qRcode. Its what I did and the connection worked without having to change the IP address

0

click 'npm start', open the browser where your application is running, and on the bottom left corner, you will find the QR code.

Above the QR code, three options are displayed saying 'Connection: Tunnel | LAN | Local' which is defaulted to 'LAN'. Just change it to 'Local'.

Your application will be up and running.

0

For me, something completely different worked under Windows. My pc has multiple network interfaces and the LAN URL points to a different one than that the mobile device can connect to.

This was quickly solved by deactivating all unnecessary network adapters.

(Setting the REACT_NATIVE_PACKAGER_HOSTNAME environment variable did not work for me.) And of course I was on the private network and had disabled the firewall for it until I configured it.

Alternatively, to avoid having to deactivate a network adapter, you can also adjust the metrics or priority of the adapters like this:

  1. goto Control Panel > Network and Internet > Network Connections
  2. right click the desired connection (Higher Priority Connection)
  3. click Properties > Internet Protocol Version 4
  4. click Properties > Advanced
  5. Uncheck 'Automatic Metric
  6. enter 10 in 'Interface Metric
  7. Click OK
0

if the above solutions don't work for you, remove the .expo directory and try again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.