Vite not recognized when executing npm run dev in Vue 3 project

I’m having trouble with my Vue 3 application. Every time I try to start the development server using npm run dev, I get an error saying the vite command is not found.

The terminal output shows:

[email protected] dev
vite
sh: vite: command not found

I checked my package.json file and the dev script is correctly configured to run vite. Here’s what it looks like:

{
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  }
}

I’m not sure why vite isn’t being recognized. Has anyone encountered this issue before? What could be causing this problem and how can I fix it?

yeah, sounds like vite isn’t installed correctly. try running npm ls vite to see if it’s there. if it’s missing, just do npm install vite --save-dev. i had the same issue when cloning projects; devDependencies usually don’t install by default.

This happens when dependencies aren’t installed or you’re working with a fresh clone. Check if there’s a node_modules directory in your project root - if it’s missing, that’s the issue. Run npm install first to get all dependencies including vite. I’ve hit this exact error tons of times setting up Vue projects on different machines. Sometimes it still breaks after installing due to PATH issues. Try running npx vite instead of npm run dev to see if vite works. If npx works but npm run dev doesn’t, you’ve got an npm config issue or script execution problem.

It seems like your node_modules might be missing or corrupted. Vite should typically be found in node_modules/.bin/ once installed correctly. A good approach is to delete your node_modules folder and package-lock.json file, then run npm install to reinstall the dependencies. I faced a similar issue recently after cloning a Vue project without installing its dependencies first. After the reinstall, everything worked fine. Additionally, you might want to check for any global vite installations that could be causing conflicts by running npm list -g vite, and remove any global instance, as local dependencies are prioritized.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.