javascript - NPM peerDependencies how to specify major version range - Stack Overflow

CaseI'm developing a mon react ponent for 2 our projects which uses 2 different version of react-

Case

I'm developing a mon react ponent for 2 our projects which uses 2 different version of 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:

{
  "peerDependencies": {
    "react": "^16.13.0",
    "react-bootstrap": "^0.33.1",
    "react-dom": "^16.13.0"
  }
}

The ponent works fine with both (used API remains the same between these 2 versions).

The problem

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 @pany/[email protected]
npm ERR! node_modules/@pany/lib
npm ERR!   @pany/lib@"1.1.6" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this mand with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

The question is

How can I specify in peerDependencies that lib can be used in both, 0.33.1 and 1.0.0 versions? Without forcing npm i to ignore these errors using --force flag.

Case

I'm developing a mon react ponent for 2 our projects which uses 2 different version of 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:

{
  "peerDependencies": {
    "react": "^16.13.0",
    "react-bootstrap": "^0.33.1",
    "react-dom": "^16.13.0"
  }
}

The ponent works fine with both (used API remains the same between these 2 versions).

The problem

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 @pany/[email protected]
npm ERR! node_modules/@pany/lib
npm ERR!   @pany/lib@"1.1.6" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this mand with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

The question is

How can I specify in peerDependencies that lib can be used in both, 0.33.1 and 1.0.0 versions? Without forcing npm i to ignore these errors using --force flag.

Share Improve this question asked Feb 12, 2021 at 10:09 DenisDenis 1782 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

So, it supports OR operator "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.

So the solution was in just:

  1. Write 2 scripts that patch package.json with correct version in peerDeeps and change package name (from @pany/package to @pany/package-legacy)
  2. Update CI/CD pipeline to build both versions of package

Not so clean, but works perfect.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745172079a4614987.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信