Last updated: Sep 30, 2022
Reading timeยท3 min

The error "'vite' is not recognized as an internal or external command, operable program or batch file" occurs when we forget to install the dependencies in a vite project.
To solve the error, run npm install to install vite before running
npm run dev.

Open your shell in your project's root directory (where your package.json is)
and run the following commands.
# ๐๏ธ if you use npm npm install npm install vite npm run dev # ๐๏ธ if you use yarn yarn install yarn add vite yarn dev
Once you run npm install or
yarn install and
install the vite package, you will be able to issue the npm run dev command
without getting any errors.

You can also prefix any vite command with
npx to resolve
the error.
npx vite --help
If the error is not resolved, try to delete your node_modules and
package-lock.json (not
package.json) files, re-run npm install and restart your IDE.
# ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json # ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json # ๐๏ธ clean npm cache npm cache clean --force # ๐๏ธ install packages npm install npm run dev
Alternatively, you can create a new Vite project with the following command.
# ๐๏ธ using NPM to create a new Vite project npm create vite@latest cd vite-project npm install npm run dev # ๐๏ธ using yarn to create a new Vite project yarn create vite cd vite-project yarn install yarn dev
If the error persists, add npm to your PATH environment variable manually.
npm to your PATH environment variableTo add npm to your PATH environment variable:




npm directory is most likely located under
%USERPROFILE%\AppData\Roaming\npm or in other words,
C:\Users\YOUR_USER\AppData\Roaming\npm.%USERPROFILE%\AppData\Roaming\npm # ๐๏ธ same as below (make sure to replace YOUR_USER) C:\Users\YOUR_USER\AppData\Roaming\npm
If you can't find it, run the npm config get prefix command.
npm config get prefix

Add the path to npm and click on "OK" twice to confirm.
Close your Command prompt application and then reopen it.
npm run dev command after you've restarted your shell.You can learn more about the related topics by checking out the following tutorials: