npm audit only for production dependencies?
Asked Answered
S

2

49

Currently, when running npm audit in a project, it checks both the dependencies and the devDependencies. I am looking for a way to only check the dependencies. Is there currently a way to do so?

Shote answered 15/5, 2018 at 14:13 Comment(2)
I couldn't find anything for now, but, apparently, there is a PR submitted about it - github.com/npm/npm/pull/20594Winograd
Awesome, so it is jut a matter of time. Thanks!Shote
C
72

Support for --production flag was released in npm 6.10.0

https://github.com/npm/cli/pull/202

npm audit --production

The --omit flag was added in npm 7.x and is now preferred.

https://docs.npmjs.com/cli/v8/commands/npm-audit/#omit

npm audit --omit=dev

Christinchristina answered 17/1, 2020 at 1:29 Comment(1)
--production seems deprecated and you should use --omit=dev instead. See my answer below for more information.Oscillator
O
6

You should use --omit=dev rather than --production according to warnings on more recent npm versions:

$ npm audit --production
npm WARN config production Use `--omit=dev` instead.

It seems to be deprecated as of npm v8.7.0. I wasn't able to confirm, but this PR seems the most relevant from my research: https://github.com/npm/cli/pull/4744

Looking into the PR's description, it's possible you should be specifying --omit peer as well.

Oscillator answered 2/7, 2022 at 17:52 Comment(1)
Looks like, according to the docs, "npm audit checks direct dependencies, devDependencies, bundledDependencies, and optionalDependencies, but does not check peerDependencies.", which means that --omit=peer should have no effect here, and as such shouldn't be necessary.Mosier

© 2022 - 2024 — McMap. All rights reserved.