To fix vulnerabilities with npm audit, run npm audit to see the report, then npm audit fix to apply updates that stay inside your semver ranges. Anything left over needs a manual upgrade, an overrides entry, or a documented decision to accept the risk. Avoid npm audit fix --force unless you review the breaking changes it installs.
The npm audit fix command is safe to run often, because it only edits package-lock.json and, when needed, package.json within the allowed ranges. This guide explains the report, the fix options and what to do when no automatic fix exists.
npm audit sends the dependency tree from your lockfile to the npm registry's advisory database and prints every known vulnerability that affects an installed version. It checks direct and transitive dependencies, so a problem three levels deep still appears.
The output is illustrative. Each entry shows the package, the affected range, a severity and whether a fix is available. Severities are low, moderate, high and critical, and they come from the advisory, not from how your application uses the package.
Useful options:
| Command | Purpose |
|---|---|
npm audit --omit=dev | Ignore devDependencies, useful for what ships to production |
npm audit --audit-level=high | Exit with an error only for high or critical findings |
npm audit --json | Machine-readable output for CI or dashboards |
npm audit signatures | Verify registry signatures and provenance of installed packages |
npm audit fix looks for a newer version of each vulnerable package that is outside the vulnerable range yet still satisfies the ranges in your tree. It then updates the lockfile and installs it.
Because the update obeys semver ranges, it should not break your code, but you still run the tests. To preview without changing anything:
If the vulnerable package is a transitive dependency, npm can often bump just that nested version in the lockfile without touching your package.json.
When the only patched version is a new major release, npm audit fix stops and prints a message like "fix available via npm audit fix --force" together with a "Will install ... which is a breaking change" warning.
--force installs the breaking version, which can change APIs and drop Node.js versions. Use it only on a branch, read the changelog of every package it lists, and run the full test suite. Often a better route is to upgrade the parent package yourself, for example npm install some-parent@latest, so the fixed child version arrives through a normal, reviewed upgrade.
Some findings have no automatic fix. Work through these options in order.
npm install parent@latest and reading its release notes.npm explain package-name to see which dependency chain installs the vulnerable version.overrides field in package.json.An override pins a transitive dependency to a fixed version:
After editing, run npm install, then npm audit again. Overrides are a stopgap: remove them when the parent package ships its own fix, otherwise they hide future incompatibilities. Yarn uses resolutions and pnpm uses pnpm.overrides for the same job.
Make audits repeatable so new advisories are noticed quickly.
npm ci installs exactly what the lockfile says, then the audit fails the job only for serious production issues. Run the same check on a schedule, for example weekly, because new advisories appear for versions you already deployed. Dependabot security updates or Renovate can open pull requests for fixes automatically.
Keep these points in mind when judging findings:
npm audit fails without package-lock.json, so commit it.Yes in most cases, because it stays inside your semver ranges and only changes versions that fix an advisory. Run your tests afterwards, and use --dry-run first if you want to preview.
No patched version exists inside your ranges, or the fix needs a major upgrade or a change in an abandoned parent package. Use npm explain, upgrade the parent, or add an overrides entry.
Only on a separate branch and after reading what it will install. It can introduce breaking changes, so a manual upgrade of the parent package is usually safer.
They matter less for production but still affect developer machines and CI. Check them with npm audit and prioritise the production set with --omit=dev.
Run npm audit to list known vulnerabilities, npm audit fix to apply compatible fixes, and treat --force as a reviewed major upgrade rather than a shortcut. For findings without a fix, find the chain with npm explain, upgrade the parent, or add a temporary overrides entry. Automate npm audit --omit=dev --audit-level=high in CI and re-run it on a schedule.