8

I do not know why it gives me error after I type "npm start". I'm trying to open my React Native project using same WIFI. I think it is about the port.

This is the error:

Loading dependency graph...events.js:183
  throw er; // Unhandled 'error' event
  ^

Error: listen EADDRINUSE :::8081
    at Server.setupListenHandle [as _listen2] (net.js:1360:14)
    at listenInCluster (net.js:1401:12)
    at Server.listen (net.js:1485:7)
    at D:\rnprojects\testproject\node_modules\metro\src\index.js:156:18
    at new Promise (<anonymous>)
    at Object.<anonymous> 
(D:\rnprojects\testproject\node_modules\metro\src\index.js:155:12)
    at Generator.next (<anonymous>)
at step (D:\rnprojects\testproject\node_modules\metro\src\index.js:47:262)
at D:\rnprojects\testproject\node_modules\metro\src\index.js:47:422
at <anonymous>
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! testproject@0.0.1 start: `node node_modules/react-native/local- 
cli/cli.js start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the testproject@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional 
logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ASUS\AppData\Roaming\npm-cache\_logs\2018-09- 
29T06_20_58_251Z-debug.log

After npm start: enter image description here

6 Answers6

26

Probably port is already in use. I face similar issue when i first run react-native run-android and then npm start. I solve it like this: First, get the id of the process running in port 8081:

sudo lsof -i :8081

then kill it:

kill -9 ID_SHOWN_FROM_PREVIOUS_CMD 

ID_SHOWN_FROM_PREVIOUS_CMD will be something like 25534 So after it, first run npm start and then react-native run-android

angelos_lex
  • 1,173
  • 8
  • 21
  • sudo is not recognized for me. – Liza Catherine Ombyaw Sep 29 '18 at 07:45
  • It's just unix command to give the ability to user to run commands as root. – angelos_lex Sep 29 '18 at 08:05
  • I do not understand haha. What should I do? – Liza Catherine Ombyaw Sep 29 '18 at 08:16
  • I'm using Windows, btw. – Liza Catherine Ombyaw Sep 29 '18 at 08:16
  • 1
    Oh, in case you can't execute these commands because of being in windows machine, then try getting PID of PORT 8081 in windows, following [this](https://stackoverflow.com/questions/15952663/find-pid-of-process-that-use-a-port-on-windows) and then kill it following [this](https://stackoverflow.com/questions/39632667/how-to-kill-the-process-currently-using-a-port-on-localhost-in-windows). I am not keen with windows, but the logic is to find which process uses 8081 port, and kill it. – angelos_lex Sep 29 '18 at 08:21
  • Since it does't have any error code like 404 or something, and you can run the app, i do not think this is a problem. In any case, better ask a new question to a new post for this new (irrelevant) problem. – angelos_lex Sep 29 '18 at 08:41
  • I think it is working now? I was trying to "react-native run-android" but said there is not device connected. But when I reload my react native app in my phone it does not give me error. Is that good now? – Liza Catherine Ombyaw Sep 29 '18 at 08:45
5

Find the port:

netstat -a -n -o | find "8081"

You need to find the pid. Second step, kill that:

taskkill /PID 5952 /F

In this case the pid is "5952".

1

Run command in terminal:

lsof -n -i4TCP:8081 | sed '1 d' | awk '{print $2}' | xargs kill -9
Ivan Ferrer
  • 397
  • 4
  • 9
0

IN my case the process running on 8081 is required and cannot be killed. So I changed the port of Native app itself Set another port

react-native start --port=8088 # any other port you like

Then change all the instance of 8081 to 8088 in project.pbxproj i.e

node_modules/react-native/React/React.xcodeproj/project.pbxproj

Also Open project in Xcode, search for 8081 and replace with 8088.

Rebuild the project again. This is how I resolved by issue.

Binod Singh
  • 654
  • 3
  • 11
  • 20
0
lsof -i :PORT_NUMBER //To find the PID

kill -9 PID

npm start
shahaf
  • 3,828
  • 2
  • 22
  • 31
0
On a mac/ubuntu, run the following command to find id of the process which is using port 8081

 **sudo lsof -i :8081**   

you are performed this operation got one PID here. Just copy and paste in next process

Then run the following to terminate process:

 **kill -9 23583**

example: PID = 23583

thats all. Enjoy your coding

mahendren
  • 790
  • 8
  • 8