107

When I run command react-native start, it shows Packager can't listen on port 8081.

I know the issue is about software using my port 8081 .

I use Resource Monitor to see the port, but I can't find 8081, there is no 8081

Can someone show me how to find it?

enter image description here

ChrisM
  • 505
  • 6
  • 18
Morton
  • 5,380
  • 18
  • 63
  • 118
  • 1
    Take a look at [this post](http://stackoverflow.com/questions/6960019/how-do-i-find-which-application-is-using-up-my-port), you should find it. – Antoine Grandchamp Apr 15 '17 at 13:22
  • In addition to the other answers, make sure the Metro bundler isn't already running in some long forgotten terminal Window somwhere. – Lurifaxel Oct 08 '18 at 13:22
  • Refer : [https://stackoverflow.com/questions/54200727/reactnative-port-8081-issue-403-forbidden](https://stackoverflow.com/questions/54200727/reactnative-port-8081-issue-403-forbidden) – Sumit Sahoo Jan 15 '19 at 14:47

16 Answers16

178

On a mac, run the following command to find id of the process which is using port 8081
sudo lsof -i :8081
Then run the following to terminate process:
kill -9 23583

Here is how it will look like enter image description here

RC_02
  • 3,146
  • 1
  • 18
  • 20
128

You can run the packager on another port.

$ react-native start --port=8088

Alternatively, find out what is using which ports on Windows with netstat.

$ netstat -a -b -o

Netstat gives you a PID, which you can use to kill the process.

$ taskkill /pid 1234
Viktor Sec
  • 2,756
  • 1
  • 24
  • 31
35

This error is coming because some process is already running on 8081 port. Stop that process and then run your command, it will run your code. For this first list all the process which are using this port by typing

lsof -i :8081  

This command will list the process id (PID) of the process and then kill the node process by using

kill -9 <PID>  

Here PID is the process id of the node process.

Pulkit Aggarwal
  • 2,554
  • 4
  • 23
  • 33
22

That picture indeed shows that your 8081 is not in use. If suggestions above haven't helped, and your mobile device is connected to your computer via usb (and you have Android 5.0 (Lollipop) or above) you could try:

$ adb reconnect

This is not necessary in most cases, but just in case, let's reset your connection with your mobile and restart adb server. Finally:

$ adb reverse tcp:8081 tcp:8081

So, whenever your mobile device tries to access any port 8081 on itself it will be routed to the 8081 port on your PC.

Or, one could try

$ killall node
13

Ubuntu/Unix && MacOS

My Metro Bundler was stuck and there were lots of node processes running but I didn't have any other development going on besides react-native, so I ran:

$ killall -9 node

The Metro Bundler is running through node on port 8081 by default, and it can encounter issues sometimes whereby it gets stuck (usually due to pressing CTRL+S in rapid succession with hot reloading on). If you press CTRL+C to kill the react-native run-android process, you will suddenly have a bad time because react-native-run-android will get stuck on :

Scanning folders for symlinks in /home/poop/dev/some-app/node_modules (41ms)

Fix:

$ killall -9 node

$ react-native run-android

Note: if you are developing other apps at the time, killing all the node proceses may interrupt them or any node-based services you have running, so be mindful of the sweeping nature of killall -9. If you aren't running a node-based database or app or you don't mind manually restarting them, then you should be good to go.

The reason I leave this detailed answer on this semi-unrelated question is that mine is a solution to a common semi-related problem that sadly requires 2 steps to fix but luckily only takes 2 steps get back to work.

If you want to surgically remove exactly the Metro Bundler garbage on port 8081, do the steps in the answer from RC_02, which are:

$ sudo lsof -i :8081

$ kill -9 23583

(where 23583 is the process ID)

agm1984
  • 15,500
  • 6
  • 89
  • 113
7

You should kill all the processes running on port 8081 by kill -9 $(lsof -i:8081)

Nagibaba
  • 4,218
  • 1
  • 35
  • 43
6

Take the terminal and type

fuser 8081/tcp

You will get a Process id which is using port 8081 Now kill the process

kill <pid>
FortuneCookie
  • 1,756
  • 3
  • 25
  • 41
3

There is a chance for running programs on port 8081. If you install McAfee antivirus then it's agent will be running on port 8081. So, We can't use the same for other programs.

First we have to verify that the port 8081 is listening or not.

In Windows,

Open CMD and run the command to check whether any program running on the port 8081.

netstat -ano | findstr 8081

Assume that if you got output something like this,

TCP    0.0.0.0:8081           0.0.0.0:0              LISTENING       5800

Then kill the program with ID 5800 using the following command,

taskkill /pid 5800

In Linux / Mac,

Open terminal and run the command to check whether any program running on the port 8081.

sudo lsof -i :8081

Assume that if you got output something like this,

COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node     59 root   18u  IPv4 609033      0t0  TCP localhost:8081 (LISTEN)

Then kill the program with ID 609033 using the following command,

sudo kill -9 59

Alternatively, You can also run the packager on another port.

react-native start --port=8088
react-native run-android --port=8088
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
2

Check if there is already a Node server running on your machine and then close it.

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
2

Try to run in another port like 3131. Run the command:

react-native run-android --port=3131
alvaropaco
  • 1,573
  • 18
  • 29
2

This might be because of McAfee using that port. Doing simple lsof -i 8081 may not show the application and you may have to sudo it.

Do sudo lsof -i 8081 and if this command gives an output you can kill it by using sudo launchctl remove com.mcafee.agent.macmn. After this start packager again.

Sankalp
  • 1,128
  • 4
  • 14
  • 31
1

in my case, internet on emulator is down as there is no wifi signal on emulator. Resetting emulator has worked.

Rohit Mandiwal
  • 10,258
  • 5
  • 70
  • 83
0

In order to fix this issue, the process I have mentioned below.

Please cancel the current process of“react-native run-android” by CTRL + C or CMD + C

Close metro bundler(terminal) window command line which opened automatically.

Run the command again on terminal, “react-native run-android

Nirav Jain
  • 5,088
  • 5
  • 40
  • 61
0

First of all, in your device go to Dev. Option -> ADB over Network after do it:

$ adb connect <your device adb network>
$ react-native run-android 

(or run-ios, by the way)

if this has successfully your device has installed app-debug.apk, open app-debug and go to Dev. Settings -> Debug server host & port for device, type in your machine's IP address (generally, System preference -> Network), as in the example below < your machine's IP address >:8081 (whihout inequality)

finally, execute the command below

$ react-native start --port=8081

try another ports, and verify that you machine and your device are same network.

Hermanyo H
  • 134
  • 3
0

For Windows

Open PowerShell and Run as Administrator:

  1. net stop winnat

The Windows NAT Driver service was stopped successfully.

  1. net start winnat

The Windows NAT Driver service was started successfully.

EVD Image

0

I solved this issue by cleaning my Gradle cache. Using this command:

cd android
./gradlew clean