I am using react native android and having face issues to deploy the app on an android device. When I run
react-native start, it won't start dev server on port
8081
I have tried a few options mentioned at:
https://facebook.github.io/react-native/docs/troubleshooting.html
Tried to stop the process running at port number 8081, but no success
My question is that can we change the React Native dev server port from 8081 (which is a default in android however the same we can change in ios from AppDelegate.m file) to something else or any other approach
Your responses will be highly appreciated. Thanks
For AndroidOnce the emulator is running press CMD + m (Mac) or CTRL + m (Windows). Select Dev Settings and then Debug server host & port for device. Enter the url with the new port. Finally CMD + R or CTRL + R and the application should reload with the new bundle.
Go to application on devices. go to Dev Setting. Tap to Debug server host & port for device. Fill your IP address and port is 8081 (example ipaddress:8081) .
Not sure if this is documented or not[1], you can specify the port via a CLI argument, like this:
react-native start --port 9988
I found it in the source code, and it worked on my local machine :)
https://github.com/facebook/react-native/blob/master/local-cli/server/server.js#L30
[1] This is now documented here: https://facebook.github.io/react-native/docs/troubleshooting#using-a-port-other-than-8081
I know it is late but FYI, there is also another way where you can change your port permanently.
Go to your_app\node_modules\react-native\local-cli\server\server.js and change the port 8081 to 8088
which will be something like this
... module.exports = { name: 'start', func: server, description: 'starts the webserver', options: [{ command: '--port [number]', default: 8088, parse: (val) => Number(val), } ...
UPDATE TESTED ON RN 0.57:
1. If you are using custom metro config
const config = { ... server: { port: 8088, } ... };
2. And if you are not then,
Go to your_app\node_modules\react-native\local-cli\util\Config.js
const Config = { ... server: { port: process.env.RCT_METRO_PORT || 8088 //changed from 8081 } ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With