npm run - Args Not Reaching the Script - Fix the Missing "--" in CI
npm needs a -- separator to forward extra arguments to the script’s command. Without it, npm interprets the flags itself, so the underlying tool never sees them and behaves as if they were absent.
What this error means
A CI command like npm run test --coverage runs without coverage, or a flag you passed is silently ignored. npm consumed the flag as its own option instead of forwarding it to the underlying command.
# intended: pass --coverage to the test runner
npm run test --coverage
# npm treats --coverage as an npm flag; the runner never sees it
# (no coverage produced, no error)Common causes
Missing -- separator
npm parses options that precede the script’s arguments. Without --, flags after the script name are interpreted by npm, not forwarded to the command.
Assuming npm passes everything through
Unlike calling the tool directly, npm run only forwards arguments that come after --, which is easy to forget when scripting CI.
How to fix it
Add the -- separator
Place -- before the arguments meant for the underlying command.
# forward --coverage to the test runner
npm run test -- --coverageVerify the args land
- Echo the effective command in CI to confirm the flag is forwarded.
- Prefer putting stable flags in the package.json script and only pass dynamic ones after --.
- Remember the same rule applies to yarn/pnpm run for forwarded args.
How to prevent it
- Use -- to forward args through npm run.
- Bake constant flags into the script; pass only dynamic ones after --.
- Echo commands in CI to confirm argument forwarding.