npm audit fix: Auto-Patch Vulnerabilities
npm audit fix rewrites your lockfile to pull in patched dependency versions.
audit fix is convenient but can introduce breaking changes with --force. In automation, run it on a branch and open a PR rather than mutating the main build.
Common flags
--force- allow major version bumps (risky)--dry-run- preview changes--package-lock-only- update the lockfile without installing
Example in CI
Preview fixes in a scheduled job, then open a PR.
npm audit fix --dry-runIn CI
Never run audit fix --force in a blocking pipeline; it can swap in breaking majors. Prefer a bot (Dependabot/Renovate) that proposes reviewable updates.
Using this in CI
Node tooling on a runner differs from your machine in three ways that matter: CI=true is set, there is no TTY, and the Node major may not be the one you develop on.
- Pin the Node major with
setup-nodeand inengines. Native modules resolve different prebuilt binaries per major. CI=truechanges behaviour in several tools, most often by promoting warnings to errors or disabling interactive prompts.- Commands that expect a TTY will hang. Pass the non-interactive or
--yesflag explicitly. - Use
npm execornode_modules/.binrather than assuming a globally installed binary is on PATH.
Key takeaways
- Avoid
--forcein automated pipelines. - Use
--dry-runto preview. - Prefer a PR bot for reviewable updates.