EADDRINUSE: address already in use

Another program is already listening on the port your server wants, often an old copy of the same dev server that never stopped.

Terminal
Error: listen EADDRINUSE: address already in use :::3000

Also appears as

  • Error: listen EADDRINUSE: address already in use 127.0.0.1:3000
  • error when starting dev server: Error: Port 5173 is already in use
  • ⚠ Port 3000 is in use by process 48213, using available port 3001 instead.

Prompt to fix it

Starting the dev server fails with "Error: listen EADDRINUSE: address already in use" on a port. Find which process holds that port (lsof -i :PORT on macOS or Linux, netstat -ano on Windows) and tell me what it is before stopping anything. If it’s an old copy of this app’s dev server, stop it and restart. If two of our own servers share the port, give each its own port and update the URLs, CORS settings, and auth redirect URLs that depend on it. Don’t kill processes you can’t identify.

Paste into Layerwise or any AI coding tool.

What it means

A port is a numbered door on your computer, and only one server at a time can listen on each. Dev servers use fixed ones: 3000 for Next.js and many Node servers, 5173 for Vite. EADDRINUSE stands for “address in use”: something already holds that port, so your server couldn’t start. The :::3000 at the end means port 3000 on every network address.

Usually the other program is your own app. A dev server started in another terminal tab, an editor, or an AI tool’s background task keeps running after you stop looking at it. A crashed npm run dev can also leave a child process behind that still holds the port.

Some tools hide this by moving to the next free port. next dev switches to 3001 and Vite to 5174 with a one-line notice. The app loads, but sign-in redirects, OAuth callback URLs, and CORS rules set up for the old port break in confusing ways. Free the original port and keep using it.

Common causes

  • A previous npm run dev is still running in another terminal, editor window, or background task.
  • A crashed or force-closed dev server left a child process that still holds the port.
  • Two parts of the app, like a frontend and an API server, are both set to the same port.
  • Another app on your machine uses that port, such as AirPlay Receiver on port 5000 on macOS.

How to fix it

  1. Find what holds the port. On macOS or Linux, run lsof -i :3000. On Windows, run netstat -ano | findstr :3000.
  2. If it’s an old dev server, go to its terminal and press Ctrl+C. Otherwise stop it by process ID with kill <PID> on macOS or Linux, or taskkill /PID <PID> /F on Windows.
  3. Start your server again with npm run dev.
  4. If two of your own servers need to run together, give each its own port, for example PORT=3001 for the API, and update every URL that points at it.
  5. To make Vite stop with an error when its port is busy, set server.port to 5173 and server.strictPort to true in vite.config.ts.

Example fix

# macOS or Linux: see what holds port 3000, then stop it by PID.
lsof -i :3000
kill 48213

# Windows
netstat -ano | findstr :3000
taskkill /PID 48213 /F
All errors
GET http://localhost:3000/api/items net::ERR_CONNECTION_REFUSED

net::ERR_CONNECTION_REFUSED

Nothing was listening at that address and port, usually because the server isn’t running or the app is calling the wrong port.

Access to fetch at 'https://api.example.com/items' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Blocked by CORS policy

The browser hid a response from another site because that server never said your site is allowed to read it.

Access blocked: This app's request is invalid You can't sign in because this app sent an invalid request. You can try again later, or contact the developer about this issue. Error 400: redirect_uri_mismatch

Error 400: redirect_uri_mismatch

Google stopped the sign-in because the return address your app sent isn’t on the OAuth client’s list of approved redirect URIs.

Error: Cannot find module 'express' Require stack: - /Users/me/my-app/server.js

Cannot find module

Node tried to load a package or file that isn’t where the code says it is, usually because it was never installed or the path is wrong.

Build with an agent that checks its work

The Layerwise agent clicks through the live preview and reads the console, so it catches errors before you do.