"vite is not recognized ..." on "npm run dev"

Viewed 17508

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.
9 Answers

try to install the packages to make it work

npm install or npm i

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

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.

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.

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

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

npm i
npm run dev

for me I've:
1 - excuted yarn add vite
2- and then npm install

work fine !

For me this worked:

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 )

Here is what to make sure before running npm install or yarn:

 Make sure `NODE_ENV` environment variable is not set to `production` if you running locally for dev purpose.


 
Related