localhost:5173 (Vite): not working and fixes
Port 5173 is Vite’s default. How to open it, change the port and fix connection problems.
Open this address: http://localhost:5173This opens on your own computer. It only works if the program is running.
localhost:5173 is where the Vite development server runs by default. If the page does not load, check the terminal, because Vite prints the exact address it is using.
What runs on localhost:5173
- Vite dev server for React, Vue, Svelte and plain JavaScript projects
Commands to start and test port 5173
npm run devnpm run dev -- --port 5174npm run dev -- --hostFind what is using port 5173
Run these in a terminal on your computer. Nothing is sent to this site.
If localhost:5173 will not open
- Vite shows “Blocked request. This host is not allowed”
- Since Vite 6, the dev server answers only to host names in
server.allowedHosts. localhost, .localhost subdomains and IP addresses are allowed by default. Behind a tunnel or a custom host name, add it toserver.allowedHosts. Vite warns that setting it totrueallows any host and is unsafe because of DNS rebinding. - Fail instead of switching to another port
- If 5173 is busy, Vite uses the next free port. Set
server.strictPort: trueto make it exit instead, which helps when other tools expect exactly 5173. - The default address is localhost only
server.hostdefaults tolocalhost.--hostorserver.host: truelistens on every address, including your LAN. That is what you need for a phone or a container, but it also exposes the server to other devices.- Changes do not reload on WSL2
- When you edit files from Windows, WSL2 can miss the change. Vite’s docs suggest
server.watch: { usePolling: true }as a workaround. It uses more CPU. - Calling an API gives a CORS error
- Use
server.proxyto forward a path such as /api to your back end, so the browser talks only to the Vite server. - vite preview is on a different port
vite previewserves the built site on its own port, 4173 by default, not on 5173. Read the address in the terminal.- Vite started on 5174, not 5173
- Port 5173 was busy, so Vite picked the next free one. Open the exact address printed in the terminal.
- localhost refuses to connect but 127.0.0.1 works
- Newer Node versions can resolve localhost to IPv6 (::1). Open http://127.0.0.1:5173 or set
server.hostto"127.0.0.1"in vite.config. - Cannot open it from another device
- Add
--hostand use your computer’s IP address. See how to open localhost from your phone. - npm run dev: missing script
- Your package.json has no dev script. Check the scripts section, or you are in the wrong folder.
Other ports like 5173
| Port | Usually used by |
|---|---|
| localhost:3000 | React, Next.js, Express |
| localhost:4200 | Angular dev server |
| localhost:5000 | Flask |
| localhost:8000 | Django, PHP, Python |
| localhost:8080 | Tomcat, Spring Boot, Docker |
| localhost:8888 | Jupyter Notebook |
| localhost:9000 | PHP-FPM, SonarQube |
Questions about localhost:5173
- What is port 5173?
- It is the default port of Vite, the build tool behind many React, Vue and Svelte projects.
- Why did Vite use 5174 instead?
- Port 5173 was busy, so Vite moved to the next free port. Open the address printed in the terminal.