Dev.to WebDev 🛠 Dev 👁 0 📖 1 min read

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 dev works but vite does not - that is expected. npm scripts put node_modules/.bin on PATH; your interactive shell does not. Use the script or npx vite.
  • In CI / Docker - run npm ci before the build step and call npx vite build (or npm run build), never bare vite.
  • You really want it global - npm install -g vite works, 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.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.