vite: command not found
The shell couldn’t find the vite program, almost always because the project’s packages aren’t installed or the command ran in the wrong folder.
Also appears as
- sh: line 1: vite: command not found
- sh: 1: vite: not found
- 'vite' is not recognized as an internal or external command, operable program or batch file.
- zsh: command not found: vite
- sh: next: command not found
Prompt to fix it
Running the dev server or build fails with "sh: vite: command not found" (or "is not recognized as an internal or external command" on Windows). Find out why the project’s local tools are missing: check that commands run in the folder with package.json, that npm install completed without errors, and that the tool is listed in package.json. For a deploy, check the host’s root directory setting and whether NODE_ENV=production skips devDependencies. Don’t install the tool globally to work around it.
Paste into Layerwise or any AI coding tool.
What it means
When you run npm run dev, npm runs the script from package.json in a shell and adds node_modules/.bin to the places that shell looks for programs. vite, next, and similar tools live there after npm install. “Command not found” means the shell looked everywhere and found nothing. Exit code 127 in a build log means the same thing.
So the real question is why node_modules/.bin/vite is missing. A freshly cloned or downloaded project has no node_modules until you install. The command may be running in a parent folder instead of the one with package.json. And on a host, a production-only install skips devDependencies, which is where vite usually lives.
Installing the tool globally with npm install -g vite makes the message go away and creates a new problem: your machine now runs a different version from the project’s, and the build server still fails. Typing vite by itself in a terminal fails for the same reason as the error: only npm scripts and npx look in node_modules/.bin.
Common causes
- The project was cloned, exported, or downloaded, and
npm installhasn’t run yet. - The terminal or build runs in the wrong folder, such as the repo root when the app lives in
frontend/. - The host installs with
NODE_ENV=productionor--omit=dev, which skipsviteindevDependencies. - An earlier install failed partway, for example on an
ERESOLVEconflict, and leftnode_modulesincomplete.
How to fix it
- In the folder that contains
package.json, runnpm install, thennpm run dev. - Read the install output and fix any errors first, since a failed install leaves tools missing.
- On a host, set the root directory (Vercel) or base directory (Netlify) to the folder with
package.json, and removeNODE_ENV=productionfrom build-time environment variables sodevDependenciesinstall. - To run a project tool outside a script, use
npx viteso it runs the project’s own version.
Example fix
# Run these in the folder that contains package.json.
npm install
npm run dev
# Outside npm scripts, npx runs the project's own copy.
npx vite --versionRelated errors
All errorsCannot find module
Node tried to load a package or file that isn’t where the code says it is, usually because it was never installed or the path is wrong.
ERESOLVE unable to resolve dependency tree
npm stopped installing because a package only supports a different version of something your project already uses, most often React.
Command "npm run build" exited with 1
Your build script failed on the host. This line only reports the failure; the actual error is printed earlier in the build log.
Cannot find module or its corresponding type declarations
TypeScript couldn’t match an import to a file or package it understands, so the build fails even when the app runs fine in the browser.
Build with an agent that checks its work
The Layerwise agent clicks through the live preview and reads the console, so it catches errors before you do.