nodejs/node · error · Error
Missing script: "${event}"${suggestions} To see a list of s
Error message
Missing script: "${event}"${suggestions}
To see a list of scripts, run:
npm run${wsArg} What it means
Thrown by `npm run` when the requested script name is not a key in package.json's `scripts`, and the special-case `start`-on-a-server-package fallback does not apply. npm collects the script name, checks `hasOwnProperty`, then (unless `--if-present`) raises this error with a did-you-mean suggestion.
Source
Thrown at deps/npm/lib/commands/run.js:115
const { isWindowsShell } = require('../utils/is-windows.js')
scripts.env = isWindowsShell ? 'SET' : 'env'
}
pkg.scripts = scripts
if (
!Object.prototype.hasOwnProperty.call(scripts, event) &&
!(event === 'start' && (await runScript.isServerPackage(path)))
) {
if (this.npm.config.get('if-present')) {
return
}
const suggestions = require('../utils/did-you-mean.js')(pkg, event)
const wsArg = workspace && path !== this.npm.localPrefix
? ` --workspace=${pkg._id || pkg.name}`
: ''
throw new Error([
`Missing script: "${event}"${suggestions}`,
'',
'To see a list of scripts, run:',
` npm run${wsArg}`,
].join('\n'))
}
// positional args only added to the main event, not pre/post
const events = [[event, args]]
if (!this.npm.config.get('ignore-scripts')) {
if (scripts[`pre${event}`]) {
events.unshift([`pre${event}`, []])
}
if (scripts[`post${event}`]) {
events.push([`post${event}`, []])
}
}View on GitHub (pinned to 1b2de5e052)
Solutions
- Run `npm run` with no args to list available scripts and confirm the exact name.
- Add the missing script to package.json `scripts` (e.g. `"build": "..."`).
- Use `--if-present` (`npm run build --if-present`) for optional scripts in shared tooling.
- Check you are in the correct workspace: `--workspace=<pkg>` or run from the right directory.
Example fix
// before npm run biuld // after npm run build // or add "biuld" to scripts
Defensive patterns
Strategy: validation
Validate before calling
function scriptExists(pkg, name) {
return Object.prototype.hasOwnProperty.call(pkg.scripts || {}, name)
}
// wrapper:
if (!scriptExists(pkg, 'build')) {
console.warn('No build script; skipping')
} else {
run('npm run build')
} Try / catch
try {
await runNpm(['run', name])
} catch (e) {
if (/Missing script/.test(e.message)) { /* optional script, ignore */ return }
throw e
} Prevention
- Use `npm run <script> --if-present` for optional scripts in shared tooling.
- In monorepos, confirm the script exists in each workspace before invoking.
- Run `npm run` (no args) to list scripts when debugging.
When it happens
Trigger: Running `npm run <event>` where `scripts[event]` is absent and not (`event === 'start'` and `runScript.isServerPackage(path)` is true), with `--if-present` unset.
Common situations: Typing a script name wrong; expecting a script a dependency provides (e.g. `npm run build` when only `dist` exists); running in the wrong workspace/monorepo package that lacks the script; CI invoking a script removed in a refactor.
Related errors
- `npm rebuild` only supports SemVer version/range specifiers
- search must be called with arguments
- Could not read package.json from tarball
- ${argv[2]} not recognized
- ${argv[2]} not recognized
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/e5f4e43cfbf0cb57.
Report an issue: GitHub.