React native ERROR Packager can't listen on port 8081

React Native

React Native Problem Overview


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

React Native Solutions


Solution 1 - React Native

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

Solution 2 - React Native

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

Solution 3 - React Native

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.

Solution 4 - React Native

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

Solution 5 - React Native

> 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)

Solution 6 - React Native

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>

Solution 7 - React Native

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

Solution 8 - React Native

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

Solution 9 - React Native

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

react-native run-android --port=3131

Solution 10 - React Native

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.

Solution 11 - React Native

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

Solution 12 - React Native

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

Solution 13 - React Native

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

Solution 14 - React Native

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.

Solution 15 - React Native

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMortonView Question on Stackoverflow
Solution 1 - React NativeRC_02View Answer on Stackoverflow
Solution 2 - React NativeViktor SecView Answer on Stackoverflow
Solution 3 - React NativePulkit AggarwalView Answer on Stackoverflow
Solution 4 - React NativeMiodrag SmolovicView Answer on Stackoverflow
Solution 5 - React Nativeagm1984View Answer on Stackoverflow
Solution 6 - React NativeFortuneCookieView Answer on Stackoverflow
Solution 7 - React NativeNagibabaView Answer on Stackoverflow
Solution 8 - React NativeHitesh SahuView Answer on Stackoverflow
Solution 9 - React NativealvaropacoView Answer on Stackoverflow
Solution 10 - React NativeSankalpView Answer on Stackoverflow
Solution 11 - React NativeAshishView Answer on Stackoverflow
Solution 12 - React NativeCodemakerView Answer on Stackoverflow
Solution 13 - React NativeNirav JainView Answer on Stackoverflow
Solution 14 - React NativeHermanyo HView Answer on Stackoverflow
Solution 15 - React NativeNguyễn Xuân CảmView Answer on Stackoverflow