Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

How Do You Fix Vulnerabilities with npm audit?

Node.jsJavaScript
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedNov 28, 2026
6 min read

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.

Table of Contents

  • What npm audit checks
  • How npm audit fix works
  • What audit fix --force really does
  • Fixing what npm audit fix cannot
  • Running audits in CI
  • Frequently Asked Questions
    • Is npm audit fix safe to run?
    • Why does npm audit still show vulnerabilities after audit fix?
    • Should I use npm audit fix --force?
    • Do audit warnings in devDependencies matter?
  • Summary
  • Related Articles

What npm audit checks

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.

bash
text

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:

CommandPurpose
npm audit --omit=devIgnore devDependencies, useful for what ships to production
npm audit --audit-level=highExit with an error only for high or critical findings
npm audit --jsonMachine-readable output for CI or dashboards
npm audit signaturesVerify registry signatures and provenance of installed packages

How npm audit fix works

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.

bash

Because the update obeys semver ranges, it should not break your code, but you still run the tests. To preview without changing anything:

bash

If the vulnerable package is a transitive dependency, npm can often bump just that nested version in the lockfile without touching your package.json.

What audit fix --force really does

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.

bash

--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.

Fixing what npm audit fix cannot

Some findings have no automatic fix. Work through these options in order.

  1. Upgrade the direct dependency that pulls in the vulnerable package, using npm install parent@latest and reading its release notes.
  2. Use npm explain package-name to see which dependency chain installs the vulnerable version.
  3. Force a patched nested version with the overrides field in package.json.
  4. Replace the dependency with a maintained alternative when the project is abandoned.
  5. Accept the risk for now and write down why, when the vulnerable code path is not reachable in your application.

An override pins a transitive dependency to a fixed version:

json

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.

Running audits in CI

Make audits repeatable so new advisories are noticed quickly.

bash

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:

  • A dev-only vulnerability in a build tool is rarely exploitable in production, but it can matter for developer machines and CI.
  • A high severity ReDoS in a function you never call is lower risk than a moderate flaw in code that handles user input.
  • A lockfile is required: npm audit fails without package-lock.json, so commit it.

Frequently Asked Questions

Is npm audit fix safe to run?

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.

Why does npm audit still show vulnerabilities after audit fix?

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.

Should I use npm audit fix --force?

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.

Do audit warnings in devDependencies matter?

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.

Summary

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.

Related Articles

  • How Do You Update Outdated npm Packages Safely?
  • What Is the Difference Between npm, Yarn and pnpm?
  • Learn Node.js: Complete Study Roadmap from Beginner to Advanced
Share

Similar posts

  • How Do You Use fs.promises in Node.js?
  • What Is the Difference Between Sync and Async fs Methods?
  • How Do You Write and Append to a File in Node.js?
  • How Do You Read a File in Node.js with the fs Module?
  • How Do You Work with File Paths Using the path Module?
  • How Do You Use npm Workspaces for a Monorepo?
  • How Do You Publish Your Own Package to npm?
  • What Is the Difference Between npm, Yarn and pnpm?