In react app (mine is next app, the same thing), sometimes we will got the error:
warn - Port 3000 is in use, trying 3001 instead.
ready - started server on 0.0.0.0:3001, url: http://localhost:3001
although it opens a new port for us automatically, you may find you can't open that link in browser.
to find which process used the 3000
port, we use this command in Git Bash:
$ netstat -ano
it will lists all the processes.Our target is 0.0.0.0:3000
, the default port of React app , we can find a result like:
Proto Local Address Foreign Address State PID
TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 2400
so the process PID is 2400
in my case.
if you use
kill -9 PID
You will get:
$ kill -9 2400
bash: kill: (2400) - No such process
the correct method is using this command:
taskkill //F //PID xxxx
:
$ taskkill //F //PID 2400
SUCCESS: The process with PID 2400 has been terminated.
although this answer on stackoverflow got a down vote (don't know why), it works for me very well:
$ npm run dev
> dev
> next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
now we are able to start the project again.