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.

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 component 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 @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.

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.

66 thoughts on “NPM peerDependencies how to specify major version range”

Leave a Comment