Vite: why am I getting vite:command not found error?

Viewed 25

I have installed vite in my vue.js app. I start the app by typing npm run dev in the main project directory. In the package.json this is defined as:

"dev": "vite"

but if I try do run this command (or eg. vite build) 'manually' from main directory, I get an error:

bash: vite: command not found

I also figured out that when I set a new script:

"build": "vite build"

I can run this command also, although, again, running it manually will result in error as above.

This seems quite illogical to me. Can anybody explain how is it possible?

1 Answers

If you didn't install vite globally (using npm install -g), then the vite command will be in node_modules/.bin in your main directory. The npm run command temporarily adds that folder to your PATH so it can execute that command. Try running ./node_modules/.bin/vite to run it without npm.

Related