When we run next dev command then before starting the server next should check for a port number 3000 is available or not if not then next should be switch to another port instead of throwing Port 3000 is already in use. error.
If port 3000 is locked due to another process then I've kill running process on port number 3000 or need to pass a port number with -p to next dev command. In my point of view, next should be switch to an available port number instead of throwing error.
There are two ways either you've to manually close port number forcefully or you've to pass a port number to next dev command.
I believe this has been asked before and I believe it is not something they intend to do. I cannot find the issue/discussion though with the answer.
There is a discussion though asking for the same thing
I found this is a repetitive process every time I've to kill port and run the next dev script again and again.
what do you think? @jamesmosier
I've found that most of the time when port 3000 is in use already, it's because I have my Next.js app already running in a different terminal window, and I appreciate being told about the issue instead of just moving to a different port.
How frequently do you have this issue? Sounds like you should just permanently change the port you develop your Next.js app on by updating your package.json:
"dev": "next -p 4000"
If you have vercel-cli installed doing vercel dev takes care of this. It will switch to 3001 if 3000 is not available
I like the create-react-app approach.
If I run a create-react-app app before a Next project, it will start on port 3000, then when I run npm run dev on my Next project, it gives me Port 3000 is already in use.
BUT, if I start my Next project before it, it takes the port 3000 and when I start create-react-app it alerts me (@jkjustjoshing would still be told that there is something running there) and gives me the opportunity to start the project on another port:
? Something is already running on port 3000.
Would you like to run the app on another port instead? (Y/n)
Most helpful comment
I've found that most of the time when port 3000 is in use already, it's because I have my Next.js app already running in a different terminal window, and I appreciate being told about the issue instead of just moving to a different port.
How frequently do you have this issue? Sounds like you should just permanently change the port you develop your Next.js app on by updating your
package.json: