[英]NPM peerDependencies how to specify major version range
I'm developing a common react component for 2 our projects which uses 2 different version of react-bootstrap.我正在为我们的 2 个项目开发一个通用的反应组件,它使用 2 个不同版本的 react-bootstrap。
First one: "react-bootstrap": "^0.33.1"
Second one: "react-bootstrap": "^1.0.0-beta.16"
In library's packages json I have:在图书馆的包 json 我有:
{
"peerDependencies": {
"react": "^16.13.0",
"react-bootstrap": "^0.33.1",
"react-dom": "^16.13.0"
}
}
The component works fine with both (used API remains the same between these 2 versions).该组件适用于两者(使用的 API 在这两个版本之间保持相同)。
When I'm trying to install that dependency in second project I get next error:当我尝试在第二个项目中安装该依赖项时,出现下一个错误:
npm ERR! Could not resolve dependency:
npm ERR! peer react-bootstrap@"^0.33.1" from @company/lib@1.1.6
npm ERR! node_modules/@company/lib
npm ERR! @company/lib@"1.1.6" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
How can I specify in peerDependencies
that lib can be used in both, 0.33.1 and 1.0.0 versions?如何在
peerDependencies
中指定 lib 可以在 0.33.1 和 1.0.0 版本中使用? Without forcing npm i
to ignore these errors using --force
flag.在不强制
npm i
使用--force
标志忽略这些错误的情况下。
So, it supports OR operator "react-bootstrap": "^0.33.1 || ^1.0.0-beta.16"
因此,它支持 OR 运算符
"react-bootstrap": "^0.33.1 || ^1.0.0-beta.16"
but it doesn't solve the problem 'cause the package is building using old version.但这并不能解决问题,因为 package 正在使用旧版本构建。
So the solution was in just:所以解决方案只是:
@company/package
to @company/package-legacy
)@company/package
到@company/package-legacy
)Not so clean, but works perfect.不是很干净,但效果很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.