sh: vite: not found (also next, tsc) in npm run build: how to fix it
sh: 1: vite: not found, sh: next: not found or tsc: not found during npm run build (exit code 127) means the shell found no such command in node_modules/.bin. Usually the install skipped devDependencies because NODE_ENV=production or --omit=dev, the install never ran in that folder, or the tool was only installed globally on your laptop. Install it into the project and make the build's install include dev dependencies.
By Livops team, the people who build and run LivopsUpdated
As it appears in a build log (shortened; the shell’s wording varies between sh: 1: vite: not found and sh: vite: not found):
> [email protected] build
> tsc -b && vite build
sh: 1: tsc: not found
or, for Next.js:
> [email protected] build
> next build
sh: 1: next: not found
The build then stops with exit code 127. This page explains why a command that works on your machine is missing on the server, the four causes in the order they usually happen, the fix for each, and where it shows on Livops.
What does the error mean?
Two facts explain it:
- The message comes from the shell, not from npm. npm runs a script by handing the line to a shell,
/bin/shon Unix-like systems[4]. When the shell cannot find a command, it fails with exit status 127 and writes an error message[12]. Current npm passes that exit code on as its own and adds nothing[7][8], which is why the log has nonpm errorlines in the simple case. - The shell looks in
node_modules/.bin.npm runaddsnode_modules/.binto thePATHit gives the script[4], sovite,nextandtscare found there without a path. Scripts run from the root of the package folder[4]. If that folder’snode_modules/.binhas novite, the shell does not find it.
So vite: not found means one thing: when the build ran, node_modules/.bin/vite did not exist in that folder. The causes below are the ways that happens.
With npm workspaces, npm run build -w <workspace> prints its own block after the shell’s line, with the exit code in it[7]:
npm error Lifecycle script `build` failed with error:
npm error code 127
npm error workspace [email protected]
Causes, most common first
1. The install skipped devDependencies
The build tools are usually devDependencies. Vite’s own install command is npm install -D vite[9], and TypeScript’s is npm install typescript --save-dev[11]. npm describes devDependencies as tools that users of a package do not need, such as test or documentation frameworks[6], and a production install leaves them out:
- with
NODE_ENV=production, theomitsetting defaults todev[1], fornpm install[2] andnpm ci[3] alike; --omit=devdoes the same, and so does--production, its deprecated alias[1].
A platform, a Dockerfile or a CI file that sets NODE_ENV=production before the install therefore leaves vite and tsc out, and the build that follows cannot find them. Next.js is less often hit by this, because its manual install, npm i next@latest react@latest react-dom@latest, saves next to dependencies[10], but anything the build needs from devDependencies, typescript among them, is still missing.
Fix: keep the tools in devDependencies and install them for the build. Types listed in --include are installed whatever omit says, in whatever order the two are given[1]:
npm ci --include=dev
npm run build
Or set NODE_ENV=production only where the app runs, not where it is built. Note that when dev is omitted, npm also sets NODE_ENV=production for all lifecycle scripts[1]. Moving the build tools to dependencies works too, at the cost of installing them wherever the app runs.
2. node_modules is missing because the install did not run there
The build command alone does not install anything. If a CI step or a custom pipeline runs npm run build on a fresh checkout without an install before it, or runs the install in a different folder, there is no node_modules/.bin in the folder the script runs in. npm ci also deletes an existing node_modules before it installs[3], so a cached folder does not carry over either.
Fix: run the install in the same folder as the build, immediately before it:
npm ci # or npm install when there is no lockfile
npm run build
If the install itself fails, its error comes first and is the one to fix; see npm ci: package.json and package-lock.json are not in sync.
3. The tool is not in package.json at all
tsc runs on your laptop because you once ran npm install -g typescript. A global install goes into npm’s prefix folder, not into the project[2], so the project’s package.json never mentions it and no server ever installs it. TypeScript’s own docs recommend a project install over a global one, so that builds are the same on every machine[11].
Fix: add the tool to the project and commit both files:
npm install -D vite # Vite
npm install typescript --save-dev # tsc
npm i next@latest react@latest react-dom@latest # Next.js
git add package.json package-lock.json
Then check that the scripts call the tools by name, as Vite’s scaffolded project and Next.js’s installation guide do: "build": "vite build"[9], "build": "next build"[10].
4. The wrong folder in a monorepo
In a repository with apps/web/package.json and a root package.json, the build may run in one folder while the tool is listed and installed in the other. With npm workspaces, the install runs once from the root[5], and a script in one workspace is run from the root by naming it[5]:
npm install vite -D -w apps/web # list the tool in that workspace
npm ci # from the repository root
npm run build -w apps/web
Without workspaces, each folder with a package.json needs its own install, run in that folder.
How to confirm the fix locally
Reproduce the server: a clean tree, the same install, then the build.
rm -rf node_modules
NODE_ENV=production npm ci # what a production install leaves out
ls node_modules/.bin | grep -E '^(vite|next|tsc)$'
npm ci --include=dev && npm run build
If the ls line prints nothing after a production install and the last line passes, cause 1 is yours. npm ls vite shows whether the project lists the tool at all.
On Livops
-
Where it shows. The build command ends with an error, the deploy stops as
build_failed, and the previous version keeps running. The cabinet shows the code and the most useful line of the log; next to the failed build, the assistant’s button reads the log and explains what happened. See Build failed. -
Check the install above the build. Livops detects the framework, Vite and Next.js among them, and from it the install and build commands. The install runs before the build and is in the same log. With a committed
package-lock.json, the log saysFound a npm lockfile — installing exactly those versionsand runsnpm ci. -
Set the commands yourself. Change them in Settings → Install and Settings → Build, or in
livops.jsonat the root of the repository or the project folder.installandbuildare applied on every deploy, and while the file names a field, the file wins over the cabinet:{ "install": "npm ci --include=dev", "build": "npm run build" } -
Monorepos. When you create the project from GitHub, set the folder the project lives in, for example
apps/web. See Ways to deploy and Frameworks and livops.json. -
Not
vitealone as the build. A build command that starts a dev server (npm run dev,vite) never ends and runs out of time; usenpm run build.
When the tool is found but a package it imports is not, see Error: Cannot find module; for other failures that end in code 1, see npm error code 1.
Questions
What does exit code 127 mean?
The shell could not find the command. POSIX shells exit with 127 when a command is not found, and npm run passes the script's exit code on as its own. So npm run build exiting with 127 means the first word of the build script, such as vite, next or tsc, was not on the PATH.
Why does npm run build work on my laptop but not on the server?
Your laptop has a node_modules folder with devDependencies in it, or the tool installed globally. The server starts from a clean checkout, so it has only what its own install put there. If that install ran with NODE_ENV=production or --omit=dev, vite and typescript were left out.
Should vite and typescript be in dependencies or devDependencies?
devDependencies is where their own docs put them: npm install -D vite and npm install typescript --save-dev. That is fine as long as the install that runs before the build includes dev dependencies. Add --include=dev to it if anything sets NODE_ENV=production.
Why does NODE_ENV=production break the build?
With NODE_ENV=production, npm's omit setting defaults to dev, so npm install and npm ci skip devDependencies. The build tools are usually devDependencies, so their commands never reach node_modules/.bin. Install with --include=dev, or set NODE_ENV=production only for the running app.
next is in my dependencies, so why is next not found?
Then the install did not run in the folder the build runs in. Check that node_modules/.bin/next exists after the install, that the install and the build run in the same folder, and in a monorepo that the package.json listing next is the one that was installed.
How do I fix it in a monorepo?
List the tool in the package.json of the workspace that uses it, install from the repository root so every workspace gets its dependencies, and run the script there with npm run build -w followed by the workspace folder, for example apps/web.
Sources
- npm Docs — config (omit, include) (docs.npmjs.com). Checked .
- npm Docs — npm install (docs.npmjs.com). Checked .
- npm Docs — npm ci (docs.npmjs.com). Checked .
- npm Docs — npm run (docs.npmjs.com). Checked .
- npm Docs — workspaces (docs.npmjs.com). Checked .
- npm Docs — package.json (docs.npmjs.com). Checked .
- npm source — lib/commands/run.js (github.com). Checked .
- npm source — lib/utils/error-message.js (github.com). Checked .
- Vite — Getting Started (vite.dev). Checked .
- Next.js Docs — Installation (nextjs.org). Checked .
- TypeScript — Download (typescriptlang.org). Checked .
- POSIX.1-2024 — Shell Command Language (pubs.opengroup.org). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Node appRelated
- Error: Cannot find module (MODULE_NOT_FOUND) in Node.js: how to fix itError: Cannot find module 'x' with code MODULE_NOT_FOUND, or ERR_MODULE_NOT_FOUND with import, means Node.js looked for a package or file and it was not there. On a server the usual causes are a package missing from package.json, a devDependency the install skipped, a path whose case differs from the file, a start command pointing at a file that was never built, or an ES module import without its .js extension.
- npm failed with return code 1 (npm ERR! code 1): how to fix the buildnpm failed with return code 1, or npm install exited with 1, is npm ERR! code 1 in newer npm: it only says that a script npm ran exited with code 1. The real error is printed above it: usually a compile or type error, a lockfile out of sync with package.json, or a dependency whose install script failed. Find the first error line above code 1, fix that, and the build passes.
- npm ci can only install packages when your package.json and package-lock.json are in sync: how to fix itnpm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync (npm error code EUSAGE) means the committed lockfile no longer matches package.json: a dependency was added or changed without re-running npm install, or the lockfile was not committed. Run npm install locally, commit package.json and package-lock.json together, and npm ci passes.
- import.meta.env.VITE_API_URL is undefined in production: why Vite env variables stop working after deployimport.meta.env.VITE_API_URL is undefined in production when Vite did not have the variable at the moment it built the site: Vite writes the values into the files at build time, so a variable set only where the site runs is never seen. The other usual causes: a name without the VITE_ prefix, a .env.local file that is ignored by git and never reaches the build server, a value kept in .env.development, and process.env in client code. Set the variable where the build runs, with the prefix, and build again.
- Node.js hosting in 2026: how to deploy an Express appA Node.js server in production needs one long-running process that listens on the port it is given, restarts when it crashes and exits cleanly on SIGTERM. On Livops you push a repository with package.json and it runs as a web app for 39 credits a month (39,000 so'm). Here is what Node needs, and how a VPS, Render, Railway, Fly.io, DigitalOcean and Heroku compare.
- Next.js hosting without Vercel: the options comparedNext.js runs on any host that runs Node: next build, then next start, and every feature works, Server Actions and image optimization included. On Livops a repository with next in package.json runs as a server from a push for 39 credits a month (39,000 so'm), and a static export is free. Here is how Vercel, Render, Railway, Fly.io and a VPS compare.
- FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory: how to fix itNode stopped itself because V8's JavaScript heap reached its limit. Raise the limit with NODE_OPTIONS=--max-old-space-size, always below the memory the machine or container really has, then cut what the process holds: source maps and type checking in a Vite, webpack or tsc build, or the leak in a server that grows until it crashes. Set above the container's memory, the same problem comes back as exit code 137.
- sh: 1: vite: Permission denied (also next, tsc, react-scripts, nest): exit code 126 and the fixsh: 1: vite: Permission denied, with exit code 126, means the shell found node_modules/.bin/vite but was not allowed to run it: the file has no execute permission. Almost always node_modules was not installed on the machine that builds, but committed, zipped or copied from another one, often a Windows PC, and the execute bit was lost on the way. Keep node_modules out of git, uploads and images, and run a clean npm ci where the build runs. chmod +x is only a stopgap.