56

I'm using Node.js and npm for the first time, I'm trying to get Vite working, following the tutorials and documentation. But every time I run into the problem 'vite' is not recognized as an internal or external command, operable program or batch file. I have been trying to find a solution for 4 hours now but with no results.

I tried restarting pc, reinstalling node.js, several procedures to create vite project but in vain. I suppose it's my beginner's mistake, but I really don't know what to do anymore.

Commands and responses I run when I try to create a vite project:
npm create vite@latest
>> my-portfolio >> vanilla & vanilla
cd my-portfolio
npm install >>resp: up to date, audited 1 package in 21s found 0 vulnerabilities npm run dev
resp:

> my-portfolio@0.0.0 dev
> vite

'vite' is not recognized as an internal or external command,
operable program or batch file.
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
MaN8fy
  • 625
  • 1
  • 5
  • 6
  • 1
    Does your PATH variable include a vite executable? – OneCricketeer Apr 12 '22 at 14:19
  • 1
    @OneCricketeer how can I check and possibly fix this? – MaN8fy Apr 12 '22 at 14:29
  • Open Control Panel and inspect your Environment variables. The error has nothing to do with npm – OneCricketeer Apr 12 '22 at 15:34
  • 1
    @OneCricketeer I don't think vite should be in the path. `npm run dev` should use the version of vite installed with the project. Using a different version somewhere in the path could cause problems. If not for this project, then maybe for others. – Jason Goemaat Mar 28 '23 at 12:28

23 Answers23

93

try to install the packages to make it work

npm install or npm i
ericson
  • 931
  • 5
  • 6
  • But first we need to ensure that Vite is added under devDependencies in package.json file: **"vite": "^4.0.0"** – shasi kanth Mar 28 '23 at 10:48
32

For this error use the following command on your terminal in the present working directory of the project

npm install
npm run dev

first, try to install a node package manager and then run npm run dev hope it will work

Ronak Munjapara
  • 459
  • 5
  • 8
6

According to documentation https://vitejs.dev/guide/#community-templates

npm install
npm run dev
npx vite build
chriscanna
  • 106
  • 1
  • 3
5

For me I had a project I created on one computer and it had this in devDependencies:

"vite": "^3.1.0"

I did pnpm install and it reported everything was fine, but I was getting the error. I ran pnpm install vite and it installed it again with this:

"vite": "^3.1.8"

After that it worked fine. So try using npm, yarn, or pnpm to install the vite package again and see if that works.

Jason Goemaat
  • 28,692
  • 15
  • 86
  • 113
4

Install Dependency Using Below Command.

npm install

or

yarn install

If you want to add vite manually use below commands

npm i vite

or

yarn add vite

on project folder run code using below commands.

npm run dev

or

yarn dev
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Abhi Patel
  • 41
  • 2
  • this works for me, I don't how many people facing this problem, but definitely they can try this code, but we can make more simply, like after create vite project, just do one thing "yarn add vite" and then "yarn dev" that's it. happy coding – NAYMUR Apr 02 '23 at 15:03
3
yarn add vite

on project folder to add vite, and run

npm run dev

again.

  • remember to update your node version to 18, LTS from 17 might not support this installation.

update:

I try to fresh install again my Laravel 9.19, since i had update my node to version 18, npm install & npm run dev just work fine without yarn.

iRviNe48
  • 311
  • 2
  • 5
  • That update information was helpful `npm install & npm run dev`. Thanks @irvine48. – mann Feb 05 '23 at 02:17
  • thank you this is working for me. Am actually creating a frontend in react with the help of vite and then next day my facing this issue thank you for sharing your answer. – Asadullah AbdulJabbar Feb 14 '23 at 17:29
3

The following works just fine!

npx vite build
npm i
npm run dev
Nidhi
  • 41
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 03 '23 at 15:21
  • If `vite` isn't installed, how does the first step work? – General Grievance Aug 14 '23 at 14:02
2

try npm install

then npm run build

1

I found myself in the same situation.

The problem is vite.cmd is not in the system or user PATH variable, so it cannot be found when it is executed from your project folder.

To fix it, you should temporarily add the folder where vite.cmd is in your PATH variable (either for the entire system or your user). I recommend adding it just for your user, and keep in mind you should probably remove it after you stop working on that project, because this could affect future projects using the same build tools.

To do this:

  • My PC > Properties > Advanced system settings > Click on Environment Variables (alternatively just use the start button and begin typing Environment, you should get a direct link)
  • On "User variables" find "Path" and edit it.
  • Add a new entry for the folder where vite.cmd is. Example "C:\dev\reactplayground\firsttest\test01\node_modules.bin" Check your project folder to find the right path.
  • Make sure your close and open your console for this change to affect.
  • Go back to your project root folder and run "vite build", it should work now.
mihe
  • 143
  • 5
  • 10
  • Normally vite is not installed globally, it is installed under node_modules in the project directory. Running with 'npm run dev' should use the version installed with the project. Having a certain version in your global path might mess with other projects. – Jason Goemaat Mar 28 '23 at 12:24
1

Needs to install all the packages in package.json and run again

npm i
npm run dev
Sky
  • 291
  • 4
  • 5
1

Using yarn:

  1. yarn add vite
  2. Then npm install
General Grievance
  • 4,555
  • 31
  • 31
  • 45
1

Recently faced this error and I run

npm install

npm run dev

then the output was VITE v3.2.4 ready in 1913 ms

THAT'S COOL

reference LINK

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 23 '22 at 12:46
1

Check if vite is installed globally on your system. If not, you can try installing it globally by running npm install -g vite. This will make the vite command available throughout your system.

Mahek Gor
  • 11
  • 1
1

Install vite as a dev dependency first

npm i vite@latest -D

npm run dev
Arth
  • 11
  • 3
  • 1
    Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Tyler2P Aug 16 '23 at 20:22
  • Even a simple explanation like "Install vite as a dev dependency first" would be better. – General Grievance Aug 17 '23 at 12:39
1

I use Linux Ubuntu, and facing this problem, so when run npm install it install Vite but not global so i have to run npm install then run sudo npm install -g vite then run npm run dev and the problem solved with me.

0

I changed NODE_ENV environment variable to development ( earlier it was production - which should not be the case, as dev-dependencies won't get installed by npm install or yarn )

Before running npm install or yarn, make sure NODE_ENV environment variable is not set to production if you running locally for dev purpose.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Darshan Patel
  • 111
  • 1
  • 5
0

'vite' is not recognized as an internal or external command, operable program or batch file.

> vite

'vite' is not recognized as an internal or external command, operable program or batch file.

try to install the packages to make it work

npm install or npm i

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 06 '22 at 21:01
0

I had the same challenge and I was finding the error

create-vite : command not found

I resolved by running the command:

npm i create-vite

From there you can continue with running the command:

npm create vite@latest

Reference:

https://www.npmjs.com/package/create-vite
Mbote-Joseph
  • 73
  • 1
  • 4
0

npm install or npm i

helps with issue of 'vite' is not recognized After I tried npm install i could run the npm run dev after and it showed me the localhost

0

I have Gone through this Error in last Couple of Hours. My Solution will be --

  1. Go to Package.json First
  2. Delete the Package which is making Error while running (if It's Running) .
  3. If it's not the Case Make Sure ur in Right( Correct ) Repo in which vite is able to Run.
  4. If Both Cases Don't Work then Tre to install the Dependency One by One which are Present and try to Run after it .
  5. Surely Changes will be Reflected in the Terminal .
  6. Remove changes or Install dep. Others again (which are left) and u r good to go . Note - Always Keep Look at the Terminal after Single Changes . That's how u debug Code adn Improve It
0

Do the following:

  1. First npm install vite
  2. Then npm run dev
nullromo
  • 2,165
  • 2
  • 18
  • 39
Laloprince
  • 41
  • 4
0

In addition to this answer suggesting npm i before npm run dev, make sure you don't have a proxy. Sometimes the problem is with your proxy.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
-1

You need Node version 15 or higher, I had the same problem because I was using an older version of it.

Ramiro
  • 7
  • 2
  • 2
    I've got Node version 16.15.0 and also had the same problem like @MaN8fy. So Node in an older version of <15 cannot be the issue here. – ShadowGames Oct 09 '22 at 21:14