Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does npm start gives me an error about the port?

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! [email protected] start: `node node_modules/react-native/local- 
cli/cli.js start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

like image 481
Liza Catherine Ombyaw Avatar asked Sep 29 '18 06:09

Liza Catherine Ombyaw


2 Answers

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

like image 185
angelos_lex Avatar answered Oct 21 '22 22:10

angelos_lex


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".

like image 5
Manara Martins Avatar answered Oct 21 '22 21:10

Manara Martins