Search code examples
npmnext.jslocalhost

Next.js - Localhost refused to connect


Localhost

My issue

I want to learn Next.js, however when I create an empty Next.js project, I can't connect to my localhost when I run npm run dev. I am doing the following:

  1. npx create-next-app@latest
  2. I give my project a name.
  3. cd project-name
  4. npm run dev

This is all I see in the command prompt and after the last info-message, the server closes. I don't think my Next.js server starts correctly because it skips to a new line after I run npm run dev.

PS C:\Users\Username\Documents\Programmering\next13-experiment> npm run dev
[email protected] dev
next dev -p 3000

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn  - You have enabled experimental feature (appDir) in next.config.js.
info  - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

info  - Using wasm build of next-swc

PS C:\Users\Username\Documents\Programmering\next13-experiment> npx create-next-app@latest --experimental-app

What I've tried

I tried to check if there was any process using the port 3000 through netstat -ano | findstr :3000, but there was not. I couldn't find any in the Firewall Inbound Rules either.

I tried to Disable Firewall or any antivirus.

I adding 127.0.0.1 localhost to C:\Windows\System32\drivers\etc\hosts and restart my PC.

I tried to change the port in the package.json.

package.json

System

Windows 10, Node v18.15.0, Next 13.3.0, Not using any VPN


Solution

  • The solution was to uninstall Node v18.15.0, install Node v18.16.0, and then restart my PC. After doing this, the issue was resolved.