The “Vite is not recognized as an internal or external command” error is a common issue developers face when working with the Vite build tool for modern web projects. This error can be frustrating, but it is typically straightforward to resolve with the correct steps and understanding of the underlying causes. This article will guide you through the solutions to fix this error and ensure a smooth development experience with Vite.
Table of Contents
Root Causes of the Error
Vite is not installed globally
Incorrect PATH configuration
Local project setup issues
Installing Vite Globally
vite
command available from any directory in your system. Using npm
npm install -g vite
Using yarn
yarn global add vite
vite --version
Adding Vite to the Project
Installing Locally
npm install vite --save-dev
Running Local Vite Commands
npx vite
yarn vite
node_modules
folder. Configuring PATH Environment Variable
On Windows
- Open System Properties: Right-click on ‘This PC’ or ‘Computer’ on the desktop or in File Explorer, then click ‘Properties’.
- Advanced System Settings: Click on ‘Advanced system settings’ on the left.
- Environment Variables: In the System Properties window, click the ‘Environment Variables’ button.
- Edit PATH Variable: In the Environment Variables window, find and select the ‘Path’ variable in the ‘System variables’ section, then click ‘Edit’.
- Add Node.js Path: Add the path to your Node.js installation (e.g.,
C:\Program Files\nodejs
) and the npm global packages directory (e.g.,%AppData%\npm
).
On macOS and Linux
- Open Terminal: Open your terminal application.
- Edit Shell Profile: Open your shell profile file in a text editor. The file to edit depends on the shell you are using. For Bash, it is
~/.bashrc
or~/.bash_profile
. For Zsh, it is~/.zshrc
. - Add PATH Export: Add the following line to include npm global binaries in your PATH:
export PATH=$PATH:~/.npm-global/bin
- Apply Changes: Save the file and run
source ~/.bashrc
(orsource ~/.zshrc
for Zsh) to apply the changes.
Configuring PATH Environment Variable
On Windows
- Open System Properties: Right-click on ‘This PC’ or ‘Computer’ on the desktop or in File Explorer, then click ‘Properties’.
- Advanced System Settings: Click on ‘Advanced system settings’ on the left.
- Environment Variables: In the System Properties window, click the ‘Environment Variables’ button.
- Edit PATH Variable: In the Environment Variables window, find and select the ‘Path’ variable in the ‘System variables’ section, then click ‘Edit’.
- Add Node.js Path: Add the path to your Node.js installation (e.g.,
C:\Program Files\nodejs
) and the npm global packages directory (e.g.,%AppData%\npm
).
On macOS and Linux
- Open Terminal: Open your terminal application.
- Edit Shell Profile: Open your shell profile file in a text editor. The file to edit depends on the shell you are using. For Bash, it is
~/.bashrc
or~/.bash_profile
. For Zsh, it is~/.zshrc
. - Add PATH Export: Add the following line to include npm global binaries in your PATH:
export PATH=$PATH:~/.npm-global/bin
- Apply Changes: Save the file and run
source ~/.bashrc
(orsource ~/.zshrc
for Zsh) to apply the changes.
Troubleshooting Common Issues
Verify Installation
npm list -g vite
npm list vite
Reinstall Node.js and npm
Check for Conflicting Software
Final Thoughts
The “Vite is not recognized as an internal or external command” error is typically due to Vite not being installed globally, PATH environment variable misconfigurations, or project-specific setup issues. By following the steps outlined in this guide, you can resolve this error and get back to developing with Vite efficiently. Whether you choose to install Vite globally or locally, ensure your PATH is correctly set up and that you are using the appropriate commands for your setup.
Frequently Asked Questions (FAQ)
Run vite --version
in your terminal. If Vite is installed, this command will return the version number.
Try reinstalling Node.js and npm, then reinstall Vite. Also, ensure there are no conflicting software or commands in your PATH.
By following these detailed steps, you should be able to resolve the “Vite is not recognized as an internal or external command” error and continue using Vite for your web development projects.
Yes, you can use npx
to run vue-cli-service
without a global installation. This method runs the command directly from your project’s dependencies.