Forcing npm install failures on mismatched peerDependencies
Asked Answered
S

1

1

Does anyone have a technique for getting npm install to completely fail when peerDependency version mismatches are present? We frequently hit issues where peerDependency warnings go unheeded by developers, and semver mismatches cause breakage when insufficient testing is present. It would be nice if our CICD processes could bomb out due to error exit codes when attempting an install with unresolved version conflicts.

Sha answered 30/7, 2020 at 16:23 Comment(1)
It's just a warning; you could parse the output looking for it, but there's no e.g. flag to npm install that will do it.Syndetic
S
1

You can't (as far as I'm aware) do this during npm install, but you can call npm ls afterwards - if there are "extraneous, missing, and invalid packages", including missing peer dependencies, it will exit non-zero. Using the flag --depth 0 limits the output to only things you directly depend on, e.g.:

$ npm ls --depth 0
[email protected] path/to/dir
├── @codeyourfuture/[email protected]
└── UNMET PEER DEPENDENCY [email protected]

npm ERR! peer dep missing: eslint@^6.0.0, required by @codeyourfuture/[email protected]

$ echo $?
1
Syndetic answered 30/7, 2020 at 16:30 Comment(1)
Ah, great idea!Sha

© 2022 - 2024 — McMap. All rights reserved.