An npm script fails with exit code 127 because the command is not found
exit code 127Short answer
Exit code 127 is the shell saying a command was not found. npm run adds node_modules/.bin to PATH, so the command is usually missing because node_modules is empty, devDependencies were skipped by NODE_ENV=production, or the tool was never a dependency. Find the command name, then install it.
Fix it fast
1Find out which cause you have
Read the line just above the exit code: it names the command the shell could not find. Then see what is installed.
npm run ls node_modules/.bin | head2Match what you see, then jump to its fix
- 1
ls node_modules fails, or npm warns you to run npm installnode_modules is missing, so no local command existsFix - 2
Install succeeds, yet tools such as vite, tsc or eslint are not founddevDependencies were skipped because NODE_ENV is productionFix - 3
The missing command is not in ls node_modules/.bin even after a full installThe command is not a dependency of this projectFix
- 1
What does the error look like?
exit code 127
Cause 1 of 3
node_modules is missing, so no local command exists
1Check
npm run puts node_modules/.bin on PATH. With no node_modules there is no .bin, and the script's command is not found.
ls node_modules/.bin2Fix
Install the dependencies in the folder that has package.json.
npm install3Verify
The command now appears in .bin and the script runs.
ls node_modules/.bin
npm run buildConfirmed by docs.npmjs.com
Cause 2 of 3
devDependencies were skipped because NODE_ENV is production
1Check
npm leaves out devDependencies when NODE_ENV is production or when --omit=dev is used.
echo $NODE_ENV
npm config get omit2Fix
Install the dev dependencies for the build step. Build tools belong in devDependencies, so build first, then install only production packages in the final image.
npm install --include=dev3Verify
The tool is in .bin and the script runs.
ls node_modules/.binConfirmed by docs.npmjs.com
Cause 3 of 3
The command is not a dependency of this project
1Check
Only commands from packages in this project reach PATH. A tool installed on another machine, or globally there, is missing here.
grep -n "devDependencies" -A 8 package.json
command -v tsc2Fix
Add the tool as a dependency (an example name is shown) so every install gets it.
npm install --save-dev typescript3Verify
The command appears in .bin.
ls node_modules/.bin | grep tscConfirmed by docs.npmjs.com
How do I stop it coming back?
- Put every tool a script calls into package.json, never rely on a global install.
- Use npm ci in CI so node_modules always matches the lockfile.
- Do not set NODE_ENV=production before the build step.
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
Back end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
corepack enable fails: permission denied while creating the pnpm link
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm'
corepack enable writes small link files for yarn and pnpm next to your node binary.
2 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fixBack end
firebase deploy stops because the predeploy lint step failed
Error: There was an error deploying functions
The predeploy hook in firebase.json runs npm run lint before every deploy, and a failing hook cancels the deploy.
3 causes, each with a fixBack end
fluent-ffmpeg cannot find the ffmpeg or ffprobe binary
Error: Cannot find ffprobe
fluent-ffmpeg does not bundle ffmpeg.
4 causes, each with a fix