问题
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.
回答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
cyf-eslint@1.0.0 path/to/dir
├── @codeyourfuture/eslint-config-standard@2.0.1
└── UNMET PEER DEPENDENCY eslint@7.5.0
npm ERR! peer dep missing: eslint@^6.0.0, required by @codeyourfuture/eslint-config-standard@2.0.1
$ echo $?
1
来源:https://stackoverflow.com/questions/63177381/forcing-npm-install-failures-on-mismatched-peerdependencies