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 error Missing script: "build"
npm error
npm error To see a list of scripts, run:
npm error npm runCommon 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.
npm run # lists available scripts in this package
# in a monorepo, target the workspace:
npm run build -w packages/webFix the name or directory
- Match the exact script key in package.json (case and colons matter).
- Set the CI working-directory to the package that defines the script.
- 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.