Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

npm run dev fails or does nothing in a Vite project

Errorvite: command not found

Short answer

Two causes cover most failed Vite starts. Vite needs Node.js 20.19 or newer, or 22.12 or newer, so an older Node fails at launch. And a fresh clone has no node_modules folder, so the vite command is not on the path until you run npm install.

  • Applies to Vite 7, Node.js 22, npm 10
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check the Node.js version and whether the dependencies folder exists. The result points at one of the two causes.

    node -v
    ls node_modules/.bin/vite
  2. 2Match what you see, then jump to its fix

    1. 1vite: command not found, or no node_modules folderdependencies were never installedFix
    2. 2The failure appears only on one machine or in one CI job, and node -v prints an older versionNode.js is older than Vite supportsFix
    3. 3Missing script: "dev"The dev script is missing or renamed in package.jsonFix

What does the error look like?

  • vite: command not found
  • npm run dev exits straight away with an error from Node.js
  • The project was just cloned and npm run dev was the first command

Cause 1 of 3

dependencies were never installed

1Check

npm run adds node_modules/.bin to the PATH of a script. If that folder does not exist, the vite binary is not there to find.

ls node_modules | head

2Fix

Install the dependencies listed in package.json, then start again.

npm install
npm run dev

3Verify

The terminal prints the local address of the dev server.

npm run dev

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 3

Node.js is older than Vite supports

1Check

Vite requires Node.js 20.19+ or 22.12+. Compare the output of node -v with that range.

node -v

2Fix

Switch to a supported Node.js version with your version manager, then reinstall so native packages match the new runtime.

nvm install 22
nvm use 22
rm -rf node_modules
npm install

3Verify

Start the dev server again.

npm run dev

Confirmed by vite.dev

Did this fix it?

Cause 3 of 3

The dev script is missing or renamed in package.json

1Check

Open the scripts block. The default Vite template defines dev as vite, build as vite build and preview as vite preview.

grep -n -A6 '"scripts"' package.json

2Fix

Restore the script, or call vite directly.

"scripts": {
  "dev": "vite",
  "build": "vite build",
  "preview": "vite preview"
}

3Verify

Run the script by name.

npm run dev

Confirmed by vite.dev

Did this fix it?

How do I stop it coming back?

  • Pin the Node.js version in the repository (an .nvmrc file or the engines field) so everyone and CI use the same one.
  • Use npm ci in CI so installs follow the lockfile.
  • Write the install and start commands in the README.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.