npm run: Usage, Options & Common CI Errors
Run the scripts defined in your package.json.
npm run (alias of npm run-script) executes a named script from the scripts field of package.json, with node_modules/.bin on PATH so local binaries resolve.
What it does
Looks up the named key in package.json scripts and runs it in a shell with node_modules/.bin prepended to PATH. Running npm run with no script name lists all available scripts. Arguments after -- are forwarded to the underlying command.
Common usage
npm run build # run the "build" script
npm run # list all scripts
npm run test -- --watch # forward --watch to the test command
npm run lint --silent # suppress npm's own log noiseCommon CI error: missing script
CI fails with "npm error Missing script: \"build\"". The script name does not exist in package.json - usually a typo or a script that only lives on another branch. Run npm run to list the real script names and fix the workflow to match.
npm run # prints the available scripts
# then call the correct name, e.g.
npm run build:ciKey options
| Flag | Effect |
|---|---|
| -- | Pass following args to the script |
| --silent | Suppress npm log output |
| --if-present | Do not error if the script is missing |
| -ws, --workspaces | Run the script in every workspace |