在不匹配的peerDependencies上强制npm安装失败 [英] Forcing npm install failures on mismatched peerDependencies

查看:89
本文介绍了在不匹配的peerDependencies上强制npm安装失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当peerDependency版本不匹配时,是否有人有技术使 npm install 完全失败?我们经常遇到这样的问题:开发人员不注意peerDependency 警告,并且当测试不足时,semver不匹配会导致中断.如果在尝试进行具有未解决的版本冲突的安装时,如果我们的CICD进程由于错误退出代码而被炸毁,那就太好了.

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.

推荐答案

您无法(据我所知)在 npm install 期间执行此操作,但是您可以之后呼叫 npm ls -如果存在外部,丢失和无效的程序包" ,包括丢失的对等项依赖关系,它将退出非零值.使用标志-depth 0 将输出限制为仅直接依赖的内容,例如:

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

这篇关于在不匹配的peerDependencies上强制npm安装失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆