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?
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.
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.
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.
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
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
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.
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)
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>
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
You should kill all the processes running on port 8081 by kill -9 $(lsof -i:8081)
Check if there is already a Node server running on your machine and then close it.
Try to run in another port like 3131. Run the command:
react-native run-android --port=3131
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.
in my case, internet on emulator is down as there is no wifi signal on emulator. Resetting emulator has worked.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With