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.

Terminal and build log
> my-app@0.0.0 dev > vite sh: vite: command not found

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 install hasn’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=production or --omit=dev, which skips vite in devDependencies.
  • An earlier install failed partway, for example on an ERESOLVE conflict, and left node_modules incomplete.

How to fix it

  1. In the folder that contains package.json, run npm install, then npm run dev.
  2. Read the install output and fix any errors first, since a failed install leaves tools missing.
  3. On a host, set the root directory (Vercel) or base directory (Netlify) to the folder with package.json, and remove NODE_ENV=production from build-time environment variables so devDependencies install.
  4. To run a project tool outside a script, use npx vite so 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 --version
All errors
Error: Cannot find module 'express' Require stack: - /Users/me/my-app/server.js

Cannot 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.

npm error code ERESOLVE npm error ERESOLVE unable to resolve dependency tree npm error npm error While resolving: my-app@0.1.0 npm error Found: react@19.2.0 npm error node_modules/react npm error react@"^19.2.0" from the root project npm error npm error Could not resolve dependency: npm error peer react@"^16.8.5 || ^17.0.0 || ^18.0.0" from react-beautiful-dnd@13.1.1 npm error node_modules/react-beautiful-dnd npm error react-beautiful-dnd@"^13.1.1" from the root project npm error npm error Fix the upstream dependency conflict, or retry npm error this command with --force or --legacy-peer-deps npm error to accept an incorrect (and potentially broken) dependency resolution.

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.

Error: Command "npm run build" exited with 1

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.

src/App.tsx:3:20 - error TS2307: Cannot find module '@/components/Header' or its corresponding type declarations.

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.