localhost:5173: Fixing the Vite Dev Server Address

Vite serves your project on localhost:5173 when you run npm run dev, and has done since Vite 3. If that tab refuses to connect, the dev server is stopped, crashed, or moved to 5174 because 5173 was busy. Read the Local: line Vite prints; it is always the address that works.

Vite ports and what each one means
PortWhen you see itNote
5173vite or npm run devDefault dev server port
5174, 5175 and up5173 was already takenVite moves on unless strictPort is set
4173vite previewServes the production build from dist

Updated

Vite is the dev server behind most new React, Vue, Svelte and Solid projects, so 5173 shows up everywhere. Its behaviour differs from older tools in two ways that cause most confusion: it quietly changes port when 5173 is busy, and it listens only on localhost unless you ask for more.

Vite server settings that fix most port problems

vite.config.ts with a fixed port and network access

host: true listens on every address so phones, containers and WSL can connect; strictPort stops the jump to 5174.

import { defineConfig } from "vite";

export default defineConfig({
  server: {
    port: 5173,
    strictPort: true,
    host: true,
  },
});

The same options for a single run

The double dash passes the flags through npm to Vite.

npm run dev -- --host --port 5173 --strictPort

Refused to connect: what to check in order

First, the terminal: if npm run dev exited with an error, there is nothing to connect to. Missing dependencies are the common one after cloning a repo, so run npm install first.

Second, the port: compare the port in your address bar with the one Vite printed. Third, Docker and WSL 2: Vite listens on localhost inside that environment, which the host may not reach. Start it with --host, which binds to all addresses, and publish the port from the container.

Pin the port when something depends on it

OAuth redirect URLs, a backend's CORS allow list and end-to-end test configs often hard-code http://localhost:5173. When Vite silently moves to 5174, logins break with errors that look unrelated. strictPort turns that silent move into a clear startup error.

If you only need a business website rather than a local project, We.Inc builds and previews the site in your browser, so there is no local server or port to manage.

How it works

  1. Start the project with npm run dev and wait for the Local: and Network: lines.
  2. Open exactly the Local: URL Vite printed, including the port.
  3. If you need the server on your phone, a container or WSL, restart it with --host.
  4. If tools expect 5173 exactly, set strictPort so Vite fails loudly instead of moving.

Tips

  • Two terminals running npm run dev in the same project give you 5173 and 5174. Close the extra one before chasing a bug that is really an old copy of the app.
  • Network: hidden by default is normal. Vite prints 'use --host to expose' until you pass that flag.
  • A bookmark to 5173 can open an old project's server that is still running. Check the page title before debugging.
  • Port 4173 is only for vite preview, which serves the built files, so changes in your code will not appear there until you rebuild.

Frequently asked questions

What is localhost:5173?

It is the default address of the Vite development server. Projects created with npm create vite@latest open there when you run npm run dev.

Why did Vite start on 5174 instead of 5173?

Another process, usually a second Vite server, already had 5173. Vite picks the next free port by default. Stop the other server, or set server.strictPort to true so Vite exits with an error instead.

Why can't my phone open localhost:5173?

localhost on the phone means the phone itself. Start Vite with npm run dev -- --host, then open the Network: address it prints, which uses your computer's local IP, from a phone on the same network.

How do I change the Vite port?

Set server.port in vite.config.js or vite.config.ts, or run vite --port 3000. Add strictPort: true if a script or OAuth callback depends on that exact port.

localhost:5173 works in the terminal but the browser shows a blank page. Why?

The server is fine but the app failed in the browser. Open the developer tools console; an import error or an exception in your first component is the usual cause.

Related: Vite vs Next.js, localhost:3000, CORS explained, localhost:4200.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

Product

Who It's For

Features

Resources

Company

View Sitemap