'vite' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Sep 30, 2022
3 min

banner

# 'vite' is not recognized as an internal or external command

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.

vite is not recognized as internal or external command

Open your shell in your project's root directory (where your package.json is) and run the following commands.

cmd
# ๐Ÿ‘‡๏ธ 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.

run npm install

You can also prefix any vite command with npx to resolve the error.

cmd
npx vite --help

# Delete your node_modules and reinstall your dependencies

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.

cmd
# ๐Ÿ‘‡๏ธ (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
Make sure to restart your IDE and dev server if the error persists. Visual Studio Code often glitches and a reboot solves things sometimes.

Alternatively, you can create a new Vite project with the following command.

cmd
# ๐Ÿ‘‡๏ธ 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.

# Add npm to your PATH environment variable

To add npm to your PATH environment variable:

  1. Click on the Search bar and type "environment variables".
  2. Click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. In the "System variables" section, select the "Path" variable and click "Edit".

select path and click edit

  1. Click on "New" and then click "Browse".

click new browse

  1. Your npm directory is most likely located under %USERPROFILE%\AppData\Roaming\npm or in other words, C:\Users\YOUR_USER\AppData\Roaming\npm.
location
%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.

cmd
npm config get prefix

npm config get prefix

  1. Add the path to npm and click on "OK" twice to confirm.

  2. Close your Command prompt application and then reopen it.

Note that you must restart your Command prompt shell for the changes to take effect.
  1. Try to issue the npm run dev command after you've restarted your shell.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev