Fixing “sh: 1: vite: not found” in npm run dev
If npm run dev prints sh: 1: vite: not found, Vite is not installed in the project yet. If you have not run npm install, run it once in the project folder. The error will go away and the Vite dev server will start.
You see this error when you start the dev server right after creating a React or other project with npm create vite, or right after running git clone on a GitHub repository. I reproduced the error in a test environment, recorded the exact message, and confirmed that installing the dependencies fixes it.
The test environment was Ubuntu 24.04. I mainly tested with Node.js 22.23.4 (npm 10.9.9). I also ran npm run dev without npm install on Node.js 24.22.1 (npm 11.19.1) and got the same error. I created the project from the react-ts template of create-vite 9.3.4, and Vite 8.3.8 was installed. I did not test Windows, macOS, yarn, or pnpm.
The full error
In the test, I created a project with npm create vite@9.3.4 app -- --template react-ts. When it finished, it showed the next steps, npm install and npm run dev.
cd app
npm install
npm run dev
I skipped npm install and ran npm run dev. The output was as follows (exit code 127):
$ npm run dev
> app@0.0.0 dev
> vite
sh: 1: vite: not found
On Node.js 24.22.1 (npm 11.19.1), the output was exactly the same, character for character.
The > vite line shows that npm is trying to run the command written in the dev entry of scripts. In the package.json generated for this project, the dev script is just vite.
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "oxlint",
"preview": "vite preview"
},
The last line, sh: 1: vite: not found, comes not from npm but from the shell (sh) that ran the command. It means the vite command could not be found. Running sh -c vite in the same folder, without going through npm, printed the same single line.
Why vite cannot be found
The npm run-script documentation says that npm run adds node_modules/.bin to the existing PATH when it runs a script. This is why you can write the command of a package installed in the project without the node_modules/.bin/ prefix. The shell that runs scripts is /bin/sh on non-Windows systems, which is the default in the script-shell setting.
However, a project that has not had npm install run yet has no node_modules folder. In the test, the freshly created folder contained only package.json, src, vite.config.ts, and so on. vite is listed in the devDependencies of package.json as "vite": "^8.3.6", but it has not been downloaded yet. So there is no vite anywhere on the PATH given to the script, and the shell stops with "not found".
Running npm install makes it go away
Run npm install in the project folder (the folder that contains package.json). In the test, it ended with the following output:
$ npm install
9 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
This created node_modules/.bin/vite, and npm ls vite confirmed that Vite 8.3.8 was installed.
$ ls node_modules/.bin/vite && npm ls vite
node_modules/.bin/vite
app@0.0.0 /path/to/app
+-- @vitejs/plugin-react@6.3.0
| `-- vite@8.3.8 deduped
`-- vite@8.3.8
For the npm install output, I show only the last five lines. The path in the npm ls output is replaced with a placeholder.
After that, running the same npm run dev again started the dev server without the error. The output below has the color control characters removed and was stopped after 8 seconds.
$ npm run dev
> app@0.0.0 dev
> vite
VITE v8.3.8 ready in 304 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
While the server was running, fetching http://localhost:5173/ with curl returned status code 200. npm run build also finished without errors and wrote its output to the dist folder.
The same applies to a repository you git clone. The .gitignore that create-vite generates includes a node_modules line. In the test, I committed a project after running npm install, then cloned it. The cloned folder had no node_modules, and npm run dev printed the same sh: 1: vite: not found. After cloning, run npm install once first.
If the error persists after npm install, devDependencies were not installed
If you ran npm install and still see the same error, the devDependencies may not have been installed. Vite is listed under devDependencies, so if you install without them, Vite will not be installed.
The omit setting for npm install defaults to dev when the environment variable NODE_ENV is production. That means devDependencies are not installed. In the test, both of the following left npm ls vite showing (empty), and npm run dev printed the same sh: 1: vite: not found:
$ npm install --omit=dev
$ NODE_ENV=production npm install
In a folder installed with --omit=dev, running npm install again without --omit=dev installed Vite, and npm run dev then started the dev server. If you want to keep NODE_ENV=production during installation, add --include=dev, as in NODE_ENV=production npm install --include=dev. This installed Vite, and npm run dev then started the dev server.
If scripts has no dev entry at all, you get npm error Missing script: "dev" instead of this error. In that case, check the script names in the scripts section of package.json.





