Overview & Root Cause Summary: The error
error Command "vite" not found (info Visit https://yarnpkg.com/en/docs/cli/run)occurs when executing script commands such asyarn dev,yarn build, oryarn start. Yarn searches the localnode_modules/.bindirectory and workspace hierarchy for the referenced CLI binary, but fails to locate it. This commonly stems from an uninstalled or corrupted dependency tree, Yarn Berry (v2+) Plug’n’Play (PnP) mode preventing standardnode_modulesfolder generation, or executing commands from the wrong directory in a monorepo workspace.
Understanding the Root Causes
- Uninstalled or Interrupted Dependencies: The project repository was freshly cloned or branch-switched without running
yarn install, or a previous installation crashed before symlinking binaries intonode_modules/.bin/. - Yarn Berry (v2–v4) Plug’n’Play (PnP) Architecture: Modern Yarn defaults to PnP mode, storing packages in compressed zip files under
.yarn/cachewithout generating a traditionalnode_modulesdirectory, causing tools expecting local file paths to fail. - Monorepo & Workspace Misdirection: Running a package script from the root of a monorepo rather than scoping the command to the specific workspace package where the binary is installed.
- Missing Development Dependencies: The executable tool (e.g.,
vite,webpack,tsc) is listed in neitherdependenciesnordevDependenciesinpackage.json.
Step 1: Quick Fix (Run Clean Install & Verify Local Binaries)
For Yarn Classic (v1.x) projects, force Yarn to verify all installed files and recreate missing binary symlinks.
# 1. Force Yarn to check and link missing binaries:
yarn install --check-files
# 2. If node_modules is corrupted, perform a clean purge:
rm -rf node_modules yarn.lock
yarn cache clean
yarn install
# 3. Ensure vite is explicitly listed in devDependencies:
yarn add -D vite
Step 2: Configuring Yarn Berry (v2+) with nodeLinker
If you are using modern Yarn Berry (v2, v3, or v4) and require traditional node_modules compatibility, configure the nodeLinker directive in .yarnrc.yml.
# 1. Open or create .yarnrc.yml in your project root and set the linker:
echo "nodeLinker: node-modules" >> .yarnrc.yml
# 2. Re-run installation to generate standard node_modules:
yarn install
# 3. (Alternative) If maintaining PnP, invoke the tool via yarn exec:
yarn exec vite build
Step 3: Resolving Monorepo Workspace Binary Routing
In multi-package monorepos (Lerna, Turborepo, Yarn Workspaces), route commands to the target child workspace package or install shared tooling at the monorepo root.
# Option A: Target the specific workspace package directly:
yarn workspace <package-name> dev
# Option B: Navigate into the package directory:
cd packages/web-app
yarn dev
# Option C: If a tool is shared across all workspaces, install to the root with -W:
yarn add -D -W vite
Verification & Testing Steps
Confirm that the CLI executable exists in the binary path and executes successfully.
# 1. Check if the binary symlink exists:
ls -la node_modules/.bin/vite
# 2. Test direct binary execution:
yarn run vite --version
# 3. Start your development server:
yarn dev
Summary Comparison Table
| Troubleshooting Approach | Applied Scope | Yarn Version Target | Recommended Scenario |
|---|---|---|---|
yarn install --check-files |
Local node_modules/.bin |
Yarn Classic (v1.x) | Missing symlinks after Git branch switch |
nodeLinker: node-modules |
Project Config (.yarnrc.yml) |
Yarn Berry (v2–v4) | Tooling requiring traditional node_modules folder |
yarn workspace <pkg> dev |
Monorepo Workspace | All versions | Multi-package monorepos & Turborepo setups |
| Clean Reinstallation | Whole Dependency Tree | All versions | Corrupted local or global Yarn package cache |
Leave a Reply