sh: vite: command not found
vite: command not found — missing Vite binary in scripts, Docker, or CI
On this page
What causes this error
vite is not a global system command — it is a binary that npm installs into
node_modules/.bin/vite when the vite dev dependency is present. The shell prints
vite: command not found (or sh: vite: not found on Alpine’s BusyBox shell) whenever it is asked
to run vite and that binary is not on PATH. The error is about a missing or unreachable binary,
not about your Vite config.
Four situations produce it. First: dependencies were never installed in this environment — a fresh
clone, a CI job that skipped npm install, or a Docker stage that runs npm run build before
COPYing and installing package.json. Second: someone runs vite directly in the terminal
instead of through an npm script; npm adds node_modules/.bin to PATH only for the duration of
npm run, so npm run dev works while a bare vite does not. Third: a production install
(npm ci --omit=dev or NODE_ENV=production) skips devDependencies, and Vite usually lives in
devDependencies, so the build binary is absent exactly where the build runs. Fourth: a Docker
layer-cache or ordering bug copies the source and runs the build before the install layer, so the
.bin directory does not yet exist at build time.
How to fix it manually
Confirm Vite is installed: ls node_modules/.bin/vite should exist; if not, run npm install
(or npm ci) and check that vite is listed under devDependencies in package.json. Run the
build through an npm script (npm run build) rather than typing vite directly, so npm puts
node_modules/.bin on PATH. If the build runs with production-only installs, either move vite
to dependencies or drop the --omit=dev flag for the build stage. In a Dockerfile, COPY
package.json and package-lock.json first, run RUN npm ci, and only then COPY the source and
run the build — so the install layer always precedes the build layer. As a one-off, npx vite build
resolves the local binary (or fetches it) without relying on PATH.
Copy this prompt into your AI coding agent
# Goal
Fix this "vite: command not found" error with the smallest safe change. Determine why the vite
binary is missing from PATH before editing anything — do not reinstall blindly.
# Context
The full error and the command that triggered it:
<paste the exact error, e.g. "sh: vite: not found", and the npm script or shell line that ran>
Where it fails: <local terminal / Docker build / CI provider>
Is vite in dependencies or devDependencies? <paste the package.json line>
Install command used in this environment: <npm install / npm ci / npm ci --omit=dev / none>
If Docker: paste the relevant COPY / RUN lines in order.
# In-scope
- package.json dependency placement and scripts
- The install command and its flags for this environment
- Dockerfile COPY/RUN ordering for the install vs build layers
# Out-of-scope
- Changing the bundler or the Vite config
- Installing vite globally on the system
- Upgrading unrelated dependencies
- Adding new CI providers or build tools
# Verification
Run `ls node_modules/.bin/vite` — confirm the binary exists.
Run the project's build script (e.g. `npm run build`) and confirm exit code 0.
In Docker, rebuild and confirm the build stage runs after the install stage.
# Output format
1. One sentence: which of the four causes applies (no install / direct call / prod-only install / Docker order).
2. The diff (only changed files: package.json, Dockerfile, CI config).
3. The verification output, last 10 lines.
4. One line: whether vite now resolves via an npm script PATH or via npx. Why this prompt works
The four-cause enumeration forces a diagnosis instead of a reflexive npm install, which only fixes
one of the four cases and silently leaves the other three. Asking whether Vite sits in
dependencies or devDependencies catches the production-install case that reinstalling never
fixes. Requiring the Dockerfile COPY/RUN lines in order surfaces the layer-ordering bug that is
invisible from the error text alone. The output line that states how vite now resolves — npm
script PATH versus npx — confirms the fix matches the environment rather than masking the problem.
Variants by symptom
| Symptom | Likely cause | First command to try |
|---|---|---|
| Fresh clone, no node_modules | dependencies not installed | npm install |
npm run dev works, bare vite does not | PATH only set inside npm run | run via npm run or use npx vite |
| Fails only in production build / CI | devDependencies omitted | drop --omit=dev or move vite to deps |
sh: vite: not found in Alpine Docker | build runs before install | reorder COPY package.json → npm ci → COPY |
| Works locally, fails in CI | CI skipped the install step | add an explicit npm ci step |
Related errors and tools
Frequently asked questions
Why does npm run dev work but running vite alone does not?
npm only adds node_modules/.bin to PATH while an npm script runs. A bare vite typed in the shell cannot see the local binary, so run it through an npm script or use npx vite.
Why does it fail only in my production build?
A production install such as npm ci --omit=dev skips devDependencies, where Vite usually lives. Move vite to dependencies for the build stage or drop the --omit=dev flag.
How do I fix sh: vite: not found in a Docker build?
COPY package.json and the lockfile first, RUN npm ci, then COPY the source. That ordering creates node_modules/.bin before the build step runs.
Generate a fix prompt
Build a tailored AI fix prompt for this error.