vite: command not found — Fix for npm, npx & pnpm
vite: command not found happens because Vite is installed as a local project dependency, not a global binary. Running vite directly in your shell only works if the local node_modules/.bin directory is in your PATH — which it is not by default.
Fix 1: Use npx (Quickest)
npx vite
npx vite build
npx vite preview
npx looks in node_modules/.bin first, so it finds the locally installed vite without any PATH changes.
Fix 2: Use pnpm exec or yarn (if not using npm)
# pnpm
pnpm exec vite
pnpm exec vite build
# yarn
yarn vite
yarn vite build
Fix 3: Add Scripts to package.json (Recommended)
The cleanest approach — define scripts that call Vite directly:
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
}
Then run:
npm run dev
npm run build
Package manager scripts automatically add node_modules/.bin to PATH, so vite resolves correctly.
Fix 4: Install Vite Globally (Not Recommended for Teams)
npm install -g vite
This makes vite available everywhere but ties you to a specific version globally. It can conflict with projects that pin a different Vite version. Prefer the npx or script approach.
Fix 5: Vite Not Installed At All
If the project has a package.json but no node_modules yet:
npm install
# or
pnpm install
# or
yarn install
Then run npx vite or npm run dev.
Why vite: command not found After npm install -D vite
Local binaries land in node_modules/.bin/. Running vite in your shell doesn't search there. You can confirm it is installed:
ls node_modules/.bin/vite
# or
./node_modules/.bin/vite --version
If the binary exists, any of the methods above will work.
Common Error: vite: Permission Denied
chmod +x node_modules/.bin/vite
Or reinstall node_modules with:
rm -rf node_modules && npm install
Verify
npx vite --version
# 6.x.x