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.
Forcing npm install failures on mismatched peerDependencies
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
Ah, great idea! –
Sha
© 2022 - 2024 — McMap. All rights reserved.
npm install
that will do it. – Syndetic