I have a number of issues reported by npm audit, and by running npm audit fix it does fix several of them. However, doing so also breaks my build for some reason. I think I know which fix causes the issue, but I'd still like to fix the other issues.
Is there a way to have npm do whatever it does when I run npm audit fix, but only for a single issue/dependency?
I know I run npm i, but that also adds the updated dependency to package.json (even with --package-lock-only flag), which I don't want. I just want npm to update the package-lock.json, like it does when I run npm audit fix, but just for a select subset of issues.
You should be able to use
npm updateto achieve what you want here. What to do is slightly different depending on whether you are usingnpm7.x ornpm6.x. I'm using 7.x, so that's what I show below.Let's say
npm auditproduces output like this:This is indicating that we need to update
minimist,mkdirp, andextract-zip.Let's do
npm lsto get an idea of what versions and dependencies we're dealing with.Because the colorizing is kind of important, here's a screenshot of that last one:
Let's see what happens if we run
npm update minimistto just update that package. Let's usenpm ls minimistto see if anything changed. (You can also see if yourpackage-lock.jsonfile changed and do a diff.)Nope, no change. We still have the same versions we had before. OK, let's try the next one, which would be
mkdirp.That
changed 1 packageseems promising. Let's see what that did:That updated
mkdirpto 0.5.5. You can test that out and see if things still work.If you now do
npm update extract-zip, that will result in a cleannpm auditrun.Hopefully, this gives you an idea of how to update the packages one at a time without modifying
package.jsonin the process. Good luck!