110

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

3

18 Answers 18

183

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

Sign up to request clarification or add additional context in comments.

3 Comments

Works on ubuntu 18.04 also
Worked for me as well, on MacOS High Sierra
Worked for me on MacOS Big Sur, too
134

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 

Comments

36

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.

Comments

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 

Comments

14

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)

Comments

8

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

Comments

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> 

Comments

5

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 

Comments

2

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

Comments

2

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

react-native run-android --port=3131 

1 Comment

McAfee is using this port in my case. As mentioned, running in different port helps.
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.

Comments

1

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

Comments

1

just write in terminal

killall -9 node 

Then restart your project with npm start your error will be solve

1 Comment

THe answer is already there. didn't see any improvements in the pervious answer
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

Comments

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.

Comments

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

Comments

0

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

cd android ./gradlew clean 

Comments

0

I had the same problem in my React Native project. It was not accepting any ports. I deleted the node_modules folder and did npm install again. the problem was fixed.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.