VMHeaven

Troubleshooting

vite: command not found — run the local binary the right way

Vite is a per-project dependency, so your shell cannot see it. Fix 'vite: command not found' with npm scripts, npx, pnpm or yarn — and on servers and CI.

Updated 19 Sept 2026~5 min read

vite: command not found happens because Vite is not a global program. It is a per-project dependency. npm install puts its executable in node_modules/.bin inside the project, and your shell’s PATH does not include that folder. So typing vite at the prompt fails, while npm run dev works. Package-manager scripts add node_modules/.bin to the PATH for as long as they run.

If npm run dev itself fails with sh: vite: command not found or sh: 1: vite: not found, the problem is different: Vite is not in node_modules at all. Find out which case you have:

in the project directory
ls node_modules/.bin/vite     # is the binary there?
npm ls vite                   # is it declared and installed?
node --version
  • The binary exists — you only need to run it through the package manager (below).
  • No node_modules folder — dependencies were never installed. Run npm install.
  • node_modules exists, Vite is missing — either it is not in package.json, or devDependencies were skipped. The server and CI section covers the second case.

Run the local Vite, not a global one

Every package manager has a way to run a binary from the project’s own node_modules:

pick your package manager
npx vite            # npm
pnpm exec vite      # pnpm (or: pnpm vite)
yarn vite           # yarn
bunx vite           # bun

# the same works for subcommands
npx vite build
npx vite preview

Better: use package.json scripts

Projects created with npm create vite@latest already contain these scripts. If yours does not, add them. Everyone on the team, and your CI, then runs the same command with the same Vite version.

package.json
{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  }
}
then
npm run dev
npm run build

Vite is not installed at all

install dependencies
# the project already lists vite in package.json
npm install          # or: npm ci, pnpm install, yarn install

# vite is missing from package.json
npm install -D vite

For a new project, npm create vite@latest scaffolds everything, including the scripts above.

On a server, in Docker and in CI

This is where the error usually shows up during npm run build. Vite is a devDependency. When NODE_ENV=production is set, or you install with --omit=dev, npm skips devDependencies, and the build step cannot find Vite.

build on a server
npm ci --include=dev
npm run build
# serve the static output in dist/ with nginx or any web server

In Docker, a multi-stage build installs everything needed to build, then ships only the finished files:

Dockerfile
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html

Windows: “‘vite’ is not recognized”

On Windows the message is ‘vite’ is not recognized as an internal or external command. The cause and the fix are the same: use npm run dev or npx vite.

One Windows-specific trap: a node_modules folder installed on Windows does not work inside WSL or a Linux container, and the reverse is also true. Vite’s build tools include platform-specific native binaries. Delete node_modules and install again on the system that runs the build.

“vite: Permission denied”

sh: 1: vite: Permission denied means the file exists but has lost its execute bit. That typically happens after node_modules was copied from another machine, unpacked from a zip, or placed on a noexec mount. A clean reinstall is the reliable fix:

reinstall
rm -rf node_modules
npm ci          # or npm install if there is no lockfile

More on execute bits and noexec mounts: bash: Permission denied.

Should you install Vite globally?

npm install -g vite makes the bare vite command work, but it runs one global version against every project. When a project pins a different major version, or plugins that expect one, you get confusing build failures. Keep Vite local and run it through scripts or npx.

When the error changes after the fix

If Vite now starts but crashes straight away with a syntax error or a message about your Node.js version, the Node install is too old for the Vite release. Compare node --version with npm view vite engines. If Node or npx is missing entirely, see npx: command not found.

verify
npx vite --version

Front-end builds are single-thread heavy. If slow builds on a shared server get in your way, the Hi-CPU KVM line runs them on high-clock cores.

Frequently asked

Why does 'npm run dev' work but typing 'vite' does not?

Vite lives in the project's node_modules/.bin, which is not on your shell's PATH. npm, pnpm and yarn add that folder to the PATH while a script runs. Use 'npx vite' or the package.json scripts.

Why does the build fail with 'vite: not found' on my server or in CI?

Vite is a devDependency, and installs with NODE_ENV=production or --omit=dev skip devDependencies. Install with 'npm ci --include=dev' before 'npm run build'.

Should I install Vite globally?

No. A global Vite ignores the version each project pins, which leads to plugin and config mismatches. Keep it as a local devDependency and run it through scripts or npx.

More in Troubleshooting

See all