Vite dev server default ports: 5173 and 4173
Vite dev server uses TCP ports 5173 and 4173 by default. Vite tries the next available port by default, so the port it ends up on may not be the one you configured. Set server.strictPort to true, or pass --strictPort, and Vite exits when the port is already in use instead of moving on.
Key facts
| Port | Protocol | Role | Category |
|---|---|---|---|
| 5173 | TCP | dev server | Frontend |
| 4173 | TCP | vite preview server | Frontend |
What happens when the port is busy
Vite tries the next available port by default, so the port it ends up on may not be the one you configured. Set server.strictPort to true, or pass --strictPort, and Vite exits when the port is already in use instead of moving on. The same applies to vite preview, whose default port is 4173.
Change the port
vite --port 3001 --strictPort--port sets the port. --strictPort makes Vite exit if that port is already in use instead of trying the next one.
import { defineConfig } from 'vite'
export default defineConfig({
server: {
port: 3001,
strictPort: true,
},
})server.port defaults to 5173. server.strictPort is the config form of --strictPort.
vite preview --port 4174 --strictPortvite preview has its own port, 4173 by default (preview.port). preview.strictPort defaults to the value of server.strictPort.
Bind address
Listens on localhost by default (server.host defaults to 'localhost'), so other devices on your network cannot reach it. Pass --host or --host 0.0.0.0, or set server.host to 0.0.0.0 or true, to listen on all addresses, including LAN and public ones.
What else uses this port
No other tool in this dataset uses ports 5173 or 4173 as a default.
The dataset is the 12 tools on the ports index.
Find and free this port
These commands find the process that holds TCP port 5173 and stop it. They come from the Port in use command generator. PID_NUMBER stands for the process ID you read from the first command: replace it before you run the others.
lsof -nP -iTCP:5173 -sTCP:LISTEN
ps -p PID_NUMBER -o pid,ppid,user,command
kill -TERM PID_NUMBERss -ltnp 'sport = :5173'
ps -p PID_NUMBER -o pid,ppid,user,command
kill -TERM PID_NUMBERGet-NetTCPConnection -LocalPort 5173 -State Listen -ErrorAction SilentlyContinue | Select-Object LocalAddress, LocalPort, State, OwningProcess
Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = PID_NUMBER" | Select-Object ProcessId, ParentProcessId, Name, CommandLine
Stop-Process -Id PID_NUMBERRead the output of the second command before you stop anything, because the owner may be a container or another person’s process. Then run the first command again to confirm the port is free.
Next free ports
Counting up from 5173, the next three ports that no tool in this dataset uses as a default are 5174, 5175, and 5176. They are suggestions only: another program on your machine may hold any of them, so run the find command above before you choose one.
In Rig
Rig starts Vite with --port N --strictPort, where N is the project’s port. If something else holds N, Vite therefore stops instead of moving, and start_project returns a portConflict that names the owner and a suggested free port, unless you pass resolve_port=kill (stop the owner) or resolve_port=suggest (switch the project to a free port).
Collisions in practice
5173 collides with itself more than with other tools. Every Vite project on your machine asks for it, and because Vite moves to the next available port by default, the second and third projects start on neighbouring ports while an old browser tab can still sit on 5173 showing a different app. That mismatch surfaces as a stale page, or as an OAuth redirect, CORS allowlist or proxy target that names the wrong port. If anything pins a port, set strictPort so a clash fails loudly, and give each project its own fixed number.
Frequently asked questions
Why did Vite start on 5174 instead of 5173?
Something already holds 5173, for example another Vite project or a dev server you left running. Vite’s default is to try the next available port, so it moved on. Stop the other server, or set server.strictPort to true (or pass --strictPort) so Vite exits instead of moving.
What port does vite preview use, and does strictPort apply to it?
vite preview defaults to port 4173 (preview.port), separate from the dev server’s 5173. The --port and --strictPort flags work on both commands, and preview.strictPort defaults to the value of server.strictPort unless you override it.
Can I open the Vite dev server from my phone?
Not by default, because server.host is localhost. Run vite --host, or set server.host to 0.0.0.0 or true, and Vite listens on all addresses, including LAN and public ones. Do that only on a network you trust.
Sources
Busy ports in Rig
When a start fails because a port is taken, Rig shows which process owns it when it can, and lets you reclaim the port or choose another. You do not need Rig to use this page.