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 update
to achieve what you want here. What to do is slightly different depending on whether you are usingnpm
7.x ornpm
6.x. I'm using 7.x, so that's what I show below.Let's say
npm audit
produces output like this:This is indicating that we need to update
minimist
,mkdirp
, andextract-zip
.Let's do
npm ls
to 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 minimist
to just update that package. Let's usenpm ls minimist
to see if anything changed. (You can also see if yourpackage-lock.json
file 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 package
seems promising. Let's see what that did:That updated
mkdirp
to 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 audit
run.Hopefully, this gives you an idea of how to update the packages one at a time without modifying
package.json
in the process. Good luck!