localhost:5173 / npm-run-dev

When npm run dev does not bring up localhost:5173

Read the terminal before the browser: npm run dev fails at one of four points — a missing script, a missing binary, a config error, or a port that is not the one you are opening.

Check what the script actually runs

The name dev is a convention, not a rule. It runs whatever package.json says it runs, and in a framework project that is often not vite directly.

bash
$ npm run

# or read it straight out of the file
$ cat package.json

No script named dev

npm reports a missing script and lists the ones that exist. Some templates name it start, some serve. Run the one that is there.

terminal
npm error Missing script: "dev"

Available scripts are:
  build
  preview
  start

The script exists but vite is missing

The script runs and the shell cannot find the binary. npm looks in node_modules/.bin, so this means the dependency is not installed in this project — a fresh clone, an interrupted install, or an install that ran in a different directory. Installing again in the project root fixes it.

terminal
sh: vite: command not found

# Windows
'vite' is not recognized as an internal or external command

The config throws before the server starts

Vite loads vite.config.js before it binds to anything. A syntax error, a plugin that throws, or an import that does not resolve stops the start with a stack trace and no address block. Nothing is listening on 5173 in that state, so the browser error you get afterwards is a consequence, not the cause.

It started, but not on the port you are opening

Vite prints the address it actually bound to. If 5173 was taken it will have moved to 5174 and said so. A framework wrapper may set a different port entirely. Open the URL from the terminal, not the one you remember.

terminal
Port 5173 is in use, trying another one...

  ➜  Local:   http://localhost:5174/

It started and the terminal looks fine

Then the server is listening and the problem is on the way to it. Three candidates in order: you are on a different machine or container than the server (the address answers on localhost only), you typed https on a server serving http, or the app itself renders nothing. The first is a host problem, the last is not a dev-server problem at all.

The order that saves time

  • Read the terminal to the end. Vite says what it bound to, or why it did not.
  • No address block means it never started — the cause is above, in the same output.
  • An address block with a different port means it started and you are opening the wrong URL.
  • An address block and the right port means the server is fine; look at host, protocol, then your app.

# faq

Questions

npm run dev does nothing and returns immediately.

Then the script exited. Read the last lines of the output — a missing binary or a config error both end the process without an address block.

Why does it work for a colleague and not for me?

Most often because node_modules is not in the repository. Install dependencies in the project root first, then run the script again.

Should I use npm run dev or npx vite?

Use the script. It carries the flags the project expects. npx vite ignores them and can start a different server than the rest of the team runs.

The server starts but the browser says the connection was refused.

Compare the port in the terminal with the one in the address bar, and check that you are on the same machine as the server.

# next

Related

# sources

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