Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

vite build fails with exit code 127 on a hosting build

Errorsh: vite: command not found

Short answer

Exit 127 means the shell found no vite program. The vite package lives in devDependencies, and npm skips those when NODE_ENV is production. Install with dev dependencies included, or run the install before the build. npm run adds node_modules/.bin to PATH, so a working install is all it needs.

  • Applies to npm 10, Node.js 22, Vite 7
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look for the install step in the build log and check whether node_modules/.bin/vite exists after it.

    echo "NODE_ENV=$NODE_ENV"
    ls node_modules/.bin/vite
  2. 2Match what you see, then jump to its fix

    1. 1NODE_ENV=production is set during the install, and node_modules/.bin/vite is missingdevDependencies were skipped because NODE_ENV is productionFix
    2. 2npm warns about running npm install, and there is no node_modules folderNo install ran, so node_modules is empty or absentFix

What does the error look like?

  • sh: vite: command not found
  • Error: Command "vite build" exited with 127

Cause 1 of 2

devDependencies were skipped because NODE_ENV is production

1Check

With NODE_ENV=production or --production, npm does not install devDependencies. The omit setting defaults to dev in that case.

npm config get omit
grep -n -A8 devDependencies package.json | grep vite

2Fix

Install with dev dependencies included for the build step. The npm docs say an included type wins over an omitted one, and also document --production=false. Or move vite to dependencies if the build runs where dev packages are never installed.

npm install --include=dev

3Verify

The binary exists and the build starts.

ls node_modules/.bin/vite
npm run build

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 2

No install ran, so node_modules is empty or absent

1Check

npm run puts node_modules/.bin on PATH, but only if the folder exists. When it does not, npm warns you to run npm install.

ls node_modules | head -3
grep -n "\"scripts\"" -A6 package.json

2Fix

Add an install command before the build command in the pipeline.

npm install
npm run build

3Verify

The build script finds vite.

npm run build

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Run the build as npm run build, not as a bare vite command, so node_modules/.bin is on PATH.
  • Keep NODE_ENV=production for the runtime, and set it only after the install and build in a Dockerfile.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.