vite: command not found? Run the local binary the right way
First published on the VMHeaven blog: vite: command not found? Run the local binary the right way. The canonical points there; the full guide covers npm/pnpm/yarn, CI and global installs. Short answer: Vite is a local
First published on the VMHeaven blog: vite: command not found? Run the local binary the right way. The canonical points there; the full guide covers npm/pnpm/yarn, CI and global installs.
Short answer: Vite is a local devDependency, not a global command. vite: command not found (or sh: vite: command not found) almost always means you ran plain vite in a shell where the project's local binary (node_modules/.bin) is not on PATH.
The fix
Install dependencies, then run Vite through the tool that knows about node_modules/.bin:
npm install
npm run dev # uses the "dev": "vite" script in package.json
Or run the local binary directly, without a script:
npx vite
pnpm and yarn have their own:
pnpm install && pnpm dev # or: pnpm exec vite
yarn install && yarn dev # or: yarn vite
Why plain vite fails
-
npm run devworks butvitedoes not - that is expected. npm scripts putnode_modules/.binon PATH; your interactive shell does not. Use the script ornpx vite. -
In CI / Docker - run
npm cibefore the build step and callnpx vite build(ornpm run build), never barevite. -
You really want it global -
npm install -g viteworks, but pinning Vite per project is safer; versions differ between projects.
Full guide
Monorepos, vite: not found in Docker builds, Windows, and the pnpm .bin quirks are in the complete version:
vite: command not found - the complete fix
Need a box to build on? A Node-ready VPS spins up in a minute.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.