Skip to content
Latchkey

npm "Missing script" - Fix "npm run" Cannot Find the Script in CI

npm "Missing script" means the script name you passed to npm run is not defined in the package.json npm is reading. Usually it is a typo, a wrong working directory, or a workspace mismatch.

What this error means

npm run <name> fails immediately with "Missing script: <name>" and often lists the scripts that do exist. Nothing ran - npm simply did not find that script in the current package.json.

npm output
npm error Missing script: "build"
npm error
npm error To see a list of scripts, run:
npm error   npm run

Common causes

The script is not defined or misspelled

package.json has no scripts.<name> entry, or the name differs (e.g. build:prod vs build).

Wrong working directory

CI runs npm in a directory whose package.json lacks the script - common in monorepos where the script lives in a sub-package.

Workspace targeting mismatch

In a workspaces repo, the script exists in a child package but you ran it from the root (or vice versa) without -w <workspace>.

How to fix it

List scripts and run from the right place

Confirm where the script is defined, then run it there.

Terminal
npm run            # lists available scripts in this package
# in a monorepo, target the workspace:
npm run build -w packages/web

Fix the name or directory

  1. Match the exact script key in package.json (case and colons matter).
  2. Set the CI working-directory to the package that defines the script.
  3. For workspaces, use -w <name> or run from the correct child package.

How to prevent it

  • Keep script names consistent across packages.
  • Set an explicit working-directory in CI steps.
  • Document the canonical scripts in the README.

Related guides

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