Skip to content
Latchkey

npm run "spawn ENOENT" / "sh: command not found" - Fix Script Shell in CI

npm runs scripts through a shell. spawn ENOENT or sh: <cmd>: not found means the command the script tries to run does not exist on PATH - an uninstalled tool, a wrong binary name, or even a missing shell on a minimal image.

What this error means

An npm run step fails with spawn <cmd> ENOENT or sh: 1: <cmd>: not found (exit 127). The script itself is defined; the command inside it cannot be located.

npm output
> app@1.0.0 build
> rimraf dist && tsc

sh: 1: rimraf: not found
npm error code 127

Common causes

A tool used by the script is not installed

The script calls a CLI (e.g. rimraf, cross-env) that is a devDependency not installed in this job, so the shell cannot find it.

Missing shell or system command on a slim image

A minimal/distroless image may lack sh or common Unix tools the script relies on, producing ENOENT.

How to fix it

Install the tool or use a local binary

Add the missing dependency and let npm put it on the script PATH.

Terminal
npm install -D rimraf cross-env
# npm adds node_modules/.bin to the script PATH automatically:
npm run build

Check the binary name and image

  1. Verify the command name matches the installed binary (ls node_modules/.bin).
  2. On slim images, install the missing Unix tools or use a fuller base image.
  3. Avoid relying on globally-installed CLIs in CI scripts.

How to prevent it

  • Declare every CLI a script uses as a devDependency.
  • Use a base image that ships the shell/tools your scripts need.
  • Reference local binaries, not global installs.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →