Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

An npm script fails with exit code 127 because the command is not found

Errorexit code 127

Short 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.

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

Fix it fast

  1. 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 | head
  2. 2Match what you see, then jump to its fix

    1. 1ls node_modules fails, or npm warns you to run npm installnode_modules is missing, so no local command existsFix
    2. 2Install succeeds, yet tools such as vite, tsc or eslint are not founddevDependencies were skipped because NODE_ENV is productionFix
    3. 3The missing command is not in ls node_modules/.bin even after a full installThe command is not a dependency of this projectFix

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/.bin

2Fix

Install the dependencies in the folder that has package.json.

npm install

3Verify

The command now appears in .bin and the script runs.

ls node_modules/.bin
npm run build

Confirmed by docs.npmjs.com

Did this fix it?

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 omit

2Fix

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=dev

3Verify

The tool is in .bin and the script runs.

ls node_modules/.bin

Confirmed by docs.npmjs.com

Did this fix it?

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 tsc

2Fix

Add the tool as a dependency (an example name is shown) so every install gets it.

npm install --save-dev typescript

3Verify

The command appears in .bin.

ls node_modules/.bin | grep tsc

Confirmed by docs.npmjs.com

Did this fix it?

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

Next step

Want this handled for good?

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