localhost:5173 is the default port of the Vite dev server, used by React, Vue, Svelte, Solid and Preact projects created with npm create vite, and by SvelteKit. Run npm run dev and Vite serves your app with hot module replacement at http://localhost:5173. If the page says refused to connect, the dev server isn't running or picked a different port.
What runs on port 5173
| Port | What | Command |
|---|---|---|
| 5173 | Vite dev server (HMR) | npm run dev / vite |
| 4173 | vite preview, serves the built dist/ | vite build && vite preview |
| 5174, 5175... | A second Vite server when 5173 is taken | automatic |
The number is "VITE" in leetspeak (V=5, I=1, T=7, E=3). Projects on older tooling such as Create React App use localhost:3000, and Angular uses localhost:4200.
Fix "localhost:5173 refused to connect"
- Check the terminal. Vite prints
Local: http://localhost:5173/when it's ready. If it moved to 5174 because 5173 was busy, that line says so. - Try
127.0.0.1:5173. Vite resolveslocalhostusing your OS. On some Node versions it binds to IPv6::1only, so one name works and the other doesn't. Settingserver.host: '127.0.0.1'makes it explicit. - Inside Docker or WSL? Vite must listen on all interfaces:
vite --host 0.0.0.0, plus-p 5173:5173for Docker. On WSL2, file-change detection across the Windows filesystem may also needserver.watch.usePolling: true. - Opened the wrong port? After
vite build,vite previewserves on 4173, not 5173.
Find and free a busy port 5173
Vite moves to the next free port silently. If you need exactly 5173 (for an OAuth redirect URI, say), set server.strictPort: true so Vite fails instead of moving, then free the port:
# macOS / Linux
lsof -i :5173
kill -9 $(lsof -ti :5173)
# Windows
netstat -ano | findstr :5173
taskkill /PID <pid> /F
Usually the culprit is a previous npm run dev left running in another terminal or editor tab. To pick another port: npm run dev -- --port 3000, or in config:
// vite.config.js
export default {
server: { port: 3000, strictPort: true },
}
Open localhost:5173 from another device
Vite listens only on localhost unless you tell it otherwise:
npm run dev -- --host
Vite then prints a Network: http://192.168.x.x:5173/ line. Open that on your phone while it's on the same Wi-Fi. For a permanent setting use server: { host: true } in vite.config.js. If the page loads but never updates, check that your firewall isn't blocking the port.
Share localhost:5173 publicly
To let someone outside your network see the dev build, run a tunnel:
relay connect --name my-vite-app http://localhost:5173
On current Vite versions the first request through the tunnel usually fails with a message like Blocked request. This host is not allowed, telling you to add the hostname to server.allowedHosts.
Vite checks the Host header of every request so random websites can't read your dev server through DNS rebinding. Allow the tunnel's hostname explicitly:
// vite.config.js
export default {
server: {
allowedHosts: ['<hostname relay connect printed>'],
},
}
Because relay connect keeps the same URL when you reuse --name, you only do this once. Avoid allowedHosts: true on a machine that's reachable from other networks.
If your Vite app has a backend that receives webhooks (a Stripe checkout or a GitHub app), send those to the backend's port with relay forward rather than through the Vite server. See receive webhooks on localhost.
