Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native ERROR Packager can't listen on port 8081

Tags:

react-native

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

like image 889
Morton Avatar asked Apr 15 '17 11:04

Morton


People also ask

What port does react-native use?

The Metro bundler runs on port 8081. If another process is already using that port, you can either terminate that process, or change the port that the bundler uses.

How do I find my port in react-native?

Open the application in Android Studio and run the app in the emulator. Once the emulator is running press CMD + m (Mac) or CTRL + m (Windows). Select Dev Settings and then Debug server host & port for device.

How do I check my error code in react-native?

First open Developer Tools in Simulator. Then press Command+D keyboard shortcut. It will open the developer tools. To debug the JavaScript code in Chrome, select "Debug JS Remotely" from the Developer Menu.


12 Answers

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

like image 195
RC_02 Avatar answered Oct 06 '22 16:10

RC_02


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
like image 29
Viktor Sec Avatar answered Oct 06 '22 15:10

Viktor Sec


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.

like image 43
Pulkit Aggarwal Avatar answered Oct 06 '22 16:10

Pulkit Aggarwal


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)

like image 34
agm1984 Avatar answered Oct 06 '22 16:10

agm1984


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>
like image 22
FortuneCookie Avatar answered Oct 06 '22 17:10

FortuneCookie


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
like image 20
Miodrag Smolovic Avatar answered Oct 06 '22 17:10

Miodrag Smolovic


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

like image 25
Nagibaba Avatar answered Oct 06 '22 15:10

Nagibaba


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

like image 42
Hitesh Sahu Avatar answered Oct 06 '22 16:10

Hitesh Sahu


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

react-native run-android --port=3131
like image 30
alvaropaco Avatar answered Oct 06 '22 17:10

alvaropaco


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.

like image 22
Sankalp Avatar answered Oct 06 '22 16:10

Sankalp


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

like image 23
Rohit Mandiwal Avatar answered Oct 06 '22 16:10

Rohit Mandiwal


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      9 root   18u  IPv4 609033      0t0  TCP localhost:8081 (LISTEN)

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

sudo kill -9 609033

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

react-native start --port=8088
react-native run-android --port=8088
like image 39
Codemaker Avatar answered Oct 06 '22 17:10

Codemaker