localhost:5173: the Vite dev server port and how to fix it

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

PortWhatCommand
5173Vite dev server (HMR)npm run dev / vite
4173vite preview, serves the built dist/vite build && vite preview
5174, 5175...A second Vite server when 5173 is takenautomatic

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"

  1. 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.
  2. Try 127.0.0.1:5173. Vite resolves localhost using your OS. On some Node versions it binds to IPv6 ::1 only, so one name works and the other doesn't. Setting server.host: '127.0.0.1' makes it explicit.
  3. Inside Docker or WSL? Vite must listen on all interfaces: vite --host 0.0.0.0, plus -p 5173:5173 for Docker. On WSL2, file-change detection across the Windows filesystem may also need server.watch.usePolling: true.
  4. Opened the wrong port? After vite build, vite preview serves 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.

Frequently asked questions

What is localhost:5173?

localhost:5173 is the default port of the Vite development server. Any project created with npm create vite, including React, Vue, Svelte, Solid and Preact templates, and SvelteKit apps, runs on http://localhost:5173 when you run npm run dev.

What is the difference between port 5173 and 4173?

5173 is the Vite dev server with hot module replacement, started by vite or npm run dev. 4173 is vite preview, which serves the production build from the dist folder so you can check it locally after running vite build.

Why can't my phone open localhost:5173?

Vite listens only on localhost by default, so other devices cannot connect. Start it with npm run dev -- --host or set server.host to true in vite.config, then open the Network URL that Vite prints from a device on the same Wi-Fi.

What does Blocked request. This host is not allowed mean in Vite?

Vite checks the Host header of incoming requests and rejects hostnames it does not know, which happens when you open the dev server through a tunnel or a custom domain. Add that hostname to server.allowedHosts in vite.config to allow it.