localhost:5173 / preview-port

Port 4173: vite preview, not the dev server

vite preview serves the finished build from dist/ on port 4173, while the dev server on 5173 compiles your source on the fly — they are two different servers with two different ports.

The two servers side by side

Same project, different jobs. The dev server never produces the files that end up on your host; the preview server never transforms your source.

  • localhost:5173 — npm run dev. Serves source, transforms on request, hot module replacement, no bundle.
  • localhost:4173 — npm run preview. Serves dist/ as static files, exactly what a real web server would ship.

It needs a build first

preview does not build anything. Run it against a stale dist/ and you will be debugging yesterday.

bash
$ npm run build     # writes dist/
$ npm run preview   # serves dist/ on 4173

Change the preview port

preview.port is separate from server.port. Setting one does not move the other.

vite.config.js
export default defineConfig({
  server:  { port: 3000 },   // npm run dev
  preview: { port: 8080 },   // npm run preview
})

What preview catches that dev does not

Bugs that only exist after bundling. Anything depending on file paths, asset URLs, the base option, code splitting, or environment variables replaced at build time behaves differently in dist/ than it does in dev. If a bug appears only after deployment, reproduce it on 4173 first — it is the same output your host gets, without a deploy.

Preview is not a production server

It is a local static file server for checking a build. No compression tuning, no cache headers worth relying on, no hardening. Use it to look at a build, not to serve one to anybody else.

It falls back too

If 4173 is taken, preview moves to the next free port, same as the dev server. preview.strictPort makes it fail instead.

# faq

Questions

What is the default port for vite preview?

4173. The dev server uses 5173.

Why is localhost:4173 empty or outdated?

preview serves dist/. If you have not run the build since your last change, you are looking at the previous build.

Can I use vite preview in production?

No. It is a local check of a build, not a production server.

Does server.port change the preview port?

No. preview.port is a separate option.

# next

Related

# sources

Checked against the Vite documentation on 2026-09-11.