日本語

How to Fix “found N vulnerabilities” in npm

​​npm​Node.js,Security,Troubleshooting

If a line like 2 vulnerabilities (1 high, 1 critical) appears after npm install, one of the packages you installed has a version with a reported vulnerability. Run npm audit to see the details, then run npm audit fix. This fixes the ones that can be fixed within the version range in your package.json. For the rest, the warning goes away when you upgrade that package to a new major version yourself.

npm runs a dependency audit (npm audit) automatically after every npm install. If it finds vulnerabilities, it prints the count below the install result. Running npm audit prints the same count at the end. npm audit fails in CI because it prints this count and exits with code 1. The output below comes from a test environment where I deliberately installed minimist 0.2.1 and ms 0.7.0, which have reported vulnerabilities. After the fix, the result stayed at found 0 vulnerabilities even after I deleted node_modules and reinstalled.

Note

The test environment was Ubuntu 24.04, Node.js 22.23.4, and npm 10.9.9. I also used npm 6.14.18 to compare older output. For the ms upgrade from 0.7 to 2.1, I only checked two calls, ms("2 days") and ms(60000). I only tested the case where the vulnerable package is listed directly in my own package.json. I did not test a vulnerability in a dependency of a dependency, what happens when you actually run npm audit fix --force, Windows or macOS, or yarn and pnpm. The vulnerability counts and details are from the registry as of 2026-11-12.

The full message and how it looks in npm 10

I installed minimist 0.2.1 and ms 0.7.0 into an empty project created with npm init -y. The output was:

text
$ npm install minimist@0.2.1 ms@0.7.0

added 2 packages, and audited 3 packages in 435ms

2 vulnerabilities (1 high, 1 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

audited 3 packages means npm audited the dependencies after the install. The result, 2 vulnerabilities (1 high, 1 critical), means two packages have vulnerabilities: one with severity high and one with severity critical.

The two suggestions below that show the two kinds of fix. npm audit fix fixes issues without breaking compatibility. npm audit fix --force is for issues that need a major-version upgrade, as the phrase including breaking changes says.

The form that starts with found, like found 3 vulnerabilities, is the output of an older npm. When I installed the same two packages with npm 6.14.18, the last lines of the output were:

text
added 2 packages from 1 contributor and audited 2 packages in 0.247s
found 3 vulnerabilities (1 moderate, 1 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

The count was also different from npm 10: it reported 3, not 2. I read the code that prints this summary (npm-audit-report) in npm 10.9.9. It only uses found for the zero case, found 0 vulnerabilities. When there is one or more vulnerability, it prints the form 2 vulnerabilities (1 high, 1 critical) if there are two or more severity levels. If there is only one severity level, it prints the form 1 moderate severity vulnerability, which appears later in this article. The explanations below use the npm 10 output.

The install does not stop when this message appears. The exit code is 0, and both packages were installed. Also, running npm install again without any change printed the same count again below up to date. Deleting node_modules and reinstalling with npm ci gave the same result. As long as an old version is installed, the message does not go away.

See which package has which problem with npm audit

Running npm audit prints the details for each package.

text
$ npm audit
# npm audit report

minimist  <0.2.4
Severity: critical
Prototype Pollution in minimist - https://github.com/advisories/GHSA-xvch-5gv4-984h
fix available via `npm audit fix`
node_modules/minimist

ms  <=1.0.0
Severity: high
Regular Expression Denial of Service in ms - https://github.com/advisories/GHSA-3fx5-fwvr-xrjg
Vercel ms Inefficient Regular Expression Complexity vulnerability - https://github.com/advisories/GHSA-w9mr-4mfr-499f
fix available via `npm audit fix --force`
Will install ms@2.1.3, which is a breaking change
node_modules/ms

2 vulnerabilities (1 high, 1 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Each block is one package. The first line gives the package name and the range of vulnerable versions. For minimist, versions before 0.2.4 are affected. For ms, versions 1.0.0 and below are affected. Severity is the severity level. The lines below it (two lines for ms) show the titles of the advisories and the URLs of the vulnerability pages on GitHub.

The fix available via line tells you how to fix each one. minimist is fixed by npm audit fix. ms needs --force, and the next line says Will install ms@2.1.3, which is a breaking change.

When npm audit finds vulnerabilities, it exits with code 1. This is different from npm install, which exits with 0.

Fix what can be fixed within the range with npm audit fix

First I ran npm audit fix. The report for ms, which it could not fix, was printed again at the end.

text
$ npm audit fix

changed 2 packages, and audited 3 packages in 502ms

1 package is looking for funding
  run `npm fund` for details

# npm audit report

ms  <2.0.0
Severity: moderate
Vercel ms Inefficient Regular Expression Complexity vulnerability - https://github.com/advisories/GHSA-w9mr-4mfr-499f
fix available via `npm audit fix --force`
Will install ms@2.1.3, which is a breaking change
node_modules/ms

1 moderate severity vulnerability

To address all issues (including breaking changes), run:
  npm audit fix --force

npm ls minimist ms showed that minimist had gone up to 0.2.4 and ms to 0.7.3. (The project name and path in the output are replaced with example values.)

text
$ npm ls minimist ms
app@1.0.0 /path/to/app
+-- minimist@0.2.4
`-- ms@0.7.3

The package.json still has "minimist": "^0.2.1" and "ms": "^0.7.0", unchanged. Both packages only moved to newer versions within these ranges. minimist 0.2.4 fixes the problem, so it disappeared.

ms moved to 0.7.3, which removed one of the two advisories and lowered the severity from high to moderate. However, the remaining advisory is ms <2.0.0, which covers every version before 2.0.0. No version within the ^0.7.0 range is fixed, so npm audit fix cannot fix it. The exit code of npm audit fix was 1 at this point.

The npm audit documentation also says that when a fix requires changing the range written in package.json, you need --force.

Upgrade the major version yourself for what remains

With --force, npm also installs versions outside the range in package.json, including major-version updates, as described in the force section of the npm audit documentation. I did not use --force. I checked which version to move to and then installed it myself.

text
$ npm view ms dist-tags
{
  latest: '2.1.3',
  beta: '3.0.0-beta.2',
  canary: '3.0.0-canary.202508261828',
  nightly: '4.0.0-nightly.202508271359'
}

latest is 2.1.3, which is the same version that npm audit suggested.

Warning

As npm audit itself says with breaking change, your code may not work as-is after a major-version update. Before you upgrade, read the package's changelog and check whether the features your code uses have changed. In my test, ms("2 days") returned 172800000 and ms(60000) returned 1m for both ms 0.7.3 and 2.1.3.

text
$ npm install ms@latest

changed 1 package, and audited 3 packages in 353ms

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities

In package.json, ms changed to ^2.1.3, and the last line became found 0 vulnerabilities. npm audit printed only that one line and exited with code 0.

text
$ npm audit
found 0 vulnerabilities

Check that it stays fixed after a reinstall

Finally, I deleted node_modules and reinstalled with npm ci. I also deleted both node_modules and package-lock.json and ran npm install. Both gave found 0 vulnerabilities.

text
$ rm -rf node_modules && npm ci

added 2 packages, and audited 3 packages in 331ms

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities

npm ci stops with an error if package-lock.json and package.json do not match, and it does not rewrite package-lock.json. After the test, package-lock.json listed minimist 0.2.4 and ms 2.1.3. As the package-lock.json documentation explains, this file belongs in the repository. After you fix the problem, commit it together with package.json, so that other people and CI get the fixed versions when they install.

In CI, set the severity level that causes a failure with –audit-level

When you use npm audit in CI, the audit-level setting lets you set the minimum severity that makes the exit code 1.

In my test, while the critical issue remained, npm audit --audit-level=critical also exited with code 1. After npm audit fix, when only the moderate ms issue was left, the same command exited with code 0. However, the ms details were still printed. As the npm audit documentation says, this option changes only the exit code; it does not reduce what is printed.

​Posted by 86