How to Change Expo React Native Default Port 19000
I Can Change Hostname with React_Native_Packager_Hostname Env Variable but Can Not Find How to Change the Ports. I Googled and Found. Exprc but It Doesn't Work...
I can change hostname with REACT_NATIVE_PACKAGER_HOSTNAME env variable but can not find how to change the ports. I googled and found .exprc but it doesn't work for me.
Edited:
Sorry for the confusion but I would like to know how to change port with expo.
6 Answers
In your package.json file change
"start": "expo start"
to
"start": "expo start --port 19001"
npx expo start --port=<YOUR_PORT>
You can set the RCT_METRO_PORT environment variable (for Metro) and/or WEB_PORT (for Webpack), e.g.:
RCT_METRO_PORT=11111 WEB_PORT=22222 expo start
These seem to be undocumented, however, so use with care.
I spent hours with reading source codes but unable to find the config. I ended up updating startDevServerAsync.js script with the port I wanted. (I admit this is not good but I can't spend more time on just dealing with this)
$ which expo-cli
/home/shohey1226/.nvm/versions/node/v14.15.5/bin/expo-cli
$ cd ~/.nvm/versions/node/v14.15.5/lib/node_modules/expo-cli/node_modules/xdl/build/start
$ sed -i 's/19000/8080/g' startDevServerAsync.js
To change the default port, you can create an .exprc file in your project root with
{
"manifestPort": valid port number (e.g. 19002)
}
You can specify this using the following CLI command:
npx react-native start --port=<YOUR_PORT>
as documented here.