npm Scripts & Workspaces/Run script only if it exists

Avoid failing when a script is missing.

Section: Lifecycle patterns

Run script only if it exists

bash
bash
npm run lint --if-present
Explanation

Avoid failing when a script is missing.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Lifecycle patterns
Run scripts in foreground
Surface script output directly in the terminal.
OpenIn sheetbashsame section
Disable lifecycle scripts
Turn off lifecycle scripts globally or locally.
OpenIn sheetbashsame section
Run a named script
Run a package.json script.
OpenIn sheetbash2 tag match
Run a script quietly
Reduce npm log noise when running scripts.
OpenIn sheetbash2 tag match
Pass args to a script
Pass additional arguments after `--`.
OpenIn sheetbash2 tag match
Run script in all workspaces
Run a script in all workspaces.
OpenIn sheetbash2 tag match