Reputation: 1565
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 am unable to find a solution.
I tried restarting pc, reinstalling node.js and several procedures to create vite project but in vain.
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:
> [email protected] dev
> vite
'vite' is not recognized as an internal or external command,
operable program or batch file.
Upvotes: 150
Views: 432300
Reputation: 499
I had the same issue and found the cause and easy solutions.
Cause
The issue is simply that vite command's path is not known. And vite should stay in devDependencies.
Solutions
Update your file package.json like this :
"build": "./node_modules/.bin/vite build",
"dev": "vite"
Or create an alias.
This worked for me in all my environments : local and on my server.
Upvotes: 0
Reputation: 499
I had the same issue and found the cause and easy solutions.
Cause
The issue is simply that vite command's path is not known.
Solutions
Update your file package.json like this :
"build": "./node_modules/.bin/vite build",
"dev": "vite"
Or create an alias.
This worked for me in all my environments : local and on my server.
Upvotes: 0
Reputation: 11
Removing node_modules and package-lock.json, and running npm install did it for me. The state of the local files was out of sync after an outdated git pull
Upvotes: 0
Reputation: 53
Had the same issue:
Typed as instructed,
cd vite-project
npm install
npm run dev
On package.json, I had the following:
"vite": "^6.0.1"
but the message said
sh: vite: command not found
Installed the dependencies again by doing
npm install
and seems to work.
Upvotes: 2
Reputation: 252
When the NODE_ENV
environment variable is set to production, npm will not install modules listed in devDependencies. And as vite
is inside of it, it will not be installed and therefore not being recognized by npm.
Try this :
npm install --include dev
source: npm
Upvotes: 3
Reputation: 21
npm install npm run dev
And all should work; bare in mind that after running these commands and you still have issues, check on the package.json file if the scripts are being created properly.
Upvotes: 0
Reputation: 61
You may have issues with your project directory: try printing your working
directory with pwd
and see if there are any ambiguous characters (like a colon, which is the separator for $PATH
elements). If there are any ambiguous characters, move or rename the faulty directories.
On UNIX systems, the $PATH
shell variable (which defines the locations of the binaries you can execute using just their name) is separated by colons (:
): with an (unescaped) colon in a directory name, it will evaluate to two directories in the binary path, preventing you from running the local binary.
(This issue can also happen with ampersands: &
)
Source: https://vitejs.dev/guide/troubleshooting#cli
Upvotes: 0
Reputation: 113
i had the same issue none of the other comments worked. it was because i had a slash "/" on a folder name in the path to the directory i was working on
Upvotes: 1
Reputation: 15
This worked out so well for me.
First install npm using **install npm**
command in your terminal.
Then run your Node local server using **npm run dev**
command.
After that, run your Node server to production by using the following command **npm run build**
Finally, run your PHP local server using the **php artisan serve**
Upvotes: 0
Reputation: 2219
Try to install the packages to make it work
npm install
or
npm i
Upvotes: 221
Reputation: 345
with qwik i had this same issue, fixed by upgrading node from
nvm uninstall v16.0.0
to
nvm install v16.15.0
Upvotes: 0
Reputation: 21
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.
Upvotes: 2
Reputation: 139
Install vite as a dev dependency first
npm i vite@latest -D
npm run dev
Upvotes: 10
Reputation: 171
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.
Upvotes: 4
Reputation: 131
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
Upvotes: 13
Reputation: 301
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.
Upvotes: 0
Reputation: 41
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.
Upvotes: 4
Reputation: 1
I have Gone through this Error in last Couple of Hours. My Solution will be --
Upvotes: 0
Reputation: 73
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
Upvotes: 0
Reputation: 29194
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.
Upvotes: 5
Reputation: 196
According to documentation https://vitejs.dev/guide/#community-templates
npm install
npm run dev
npx vite build
Upvotes: 13
Reputation: 311
yarn add vite
on project folder to add vite, and run
npm run dev
again.
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.
Upvotes: 3
Reputation: 17
You need Node version 15 or higher, I had the same problem because I was using an older version of it.
Upvotes: 0
Reputation: 161
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:
Upvotes: 0
Reputation: 689
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
Upvotes: 54