Sumit Sahoo
Sumit Sahoo

Reputation: 3219

ReactNative port 8081 issue : 403 Forbidden

While developing using ReactNative on Windows, I am getting below 403 error. This is because port 8081 which ReactNative uses by default is being used by another program. In my case it was McAfee (Thanks McAfee for making this harder).

Command to run the project : react-native run-android

enter image description here

Upvotes: 3

Views: 1281

Answers (1)

Sumit Sahoo
Sumit Sahoo

Reputation: 3219

I searched around a lot and finally figured out how to run this project on a different port. If you have any Antivirus software installed then it may help if you disable the firewall while developing or allow connections manually through settings.

  1. Start ReactNative on a different port

    react-native start --port 9080

  2. This will open a new command prompt and start the metro bundler on port 9080 (you can use any other port you want). Wait for the dependency graph to be fully loaded.

  3. Now in a different command prompt (project directory) use the below command to build and install the app on device

    react-native run-android

  4. Now once the app is loaded on device you will see the 403 error along with the red screen. To make the device communicate on a different port use below command.

    adb reverse tcp:8081 tcp:9080

or if you have multiple device connected then provide the device id (e.g. FA6AA0301277)

adb -s FA6AA0301277 reverse tcp:8081 tcp:9080

To know the list of devices connected use below command

adb devices

That's it, now you should be able to see the index page :) Happy Coding :)

Upvotes: 3

Related Questions