The error
When you run npm run dev or vite, you see:
Port 5173 is already in use.
Use --port to specify a different port.
Vite defaults to port 5173. If an old Vite process, another dev server, or a background task is holding that port, Vite cannot start.
Fix 1: portrm (instant)
$ ptrm fix 5173
Port 5173 in use
node (PID 28091) - vite preview
Killed PID 28091. Port 5173 is free.
$ npm run dev # works now
Fix 2: Kill manually (macOS / Linux)
$ lsof -ti :5173 | xargs kill -9
On Windows:
> netstat -ano | findstr :5173
TCP 0.0.0.0:5173 0.0.0.0:0 LISTENING 28091
> taskkill /PID 28091 /F
Fix 3: Change Vite's port
If you want to keep the other process running, configure Vite to use a different port:
// vite.config.ts
import { defineConfig } from 'vite'
export default defineConfig({
server: {
port: 3000,
strictPort: true // fail if 3000 is also taken
}
})
Or as a CLI flag:
$ vite --port 3000
Fix 4: Auto-detect next available port
By default Vite already tries the next port, but only if strictPort is false (the default). If you have strictPort: true in your config, remove it or set it to false:
// vite.config.ts
export default defineConfig({
server: {
port: 5173,
strictPort: false // will try 5174, 5175, etc.
}
})
Preventing Vite port conflicts
| Cause | Prevention |
|---|---|
| Orphaned Vite process | Close terminal tabs properly or use ptrm fix |
| Multiple Vite projects | Set unique server.port per project |
| HMR WebSocket conflict | Configure server.hmr.port if custom setup |
| Vitest using same port | Vitest uses a separate port by default |
Tip: Add
ptrm fix 5173 to your package.json scripts: "predev": "ptrm fix 5173" to auto-clear the port before every npm run dev.
Never restart Vite manually again
portrm auto-detects and kills zombie Vite processes. One command, zero thought.