Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pnpm: How to install the same dependency in different versions?

When installing a package with pnpm I get this error:

ERR_PNPM_PEER_DEP_ISSUES  Unmet peer dependencies

tinacms
└─┬ @tinacms/toolkit
  ├─┬ @react-aria/listbox
  │ └── ✕ unmet peer react@"^16.8.0 || ^17.0.0-rc.1": found 18.2.0
  └─┬ @udecode/plate-headless
    └─┬ @udecode/plate-alignment
      └─┬ @udecode/plate-core
        └─┬ @radix-ui/react-slot
          ├── ✕ unmet peer react@"^16.8 || ^17.0": found 18.2.0
          └─┬ @radix-ui/react-compose-refs
            └── ✕ unmet peer react@"^16.8 || ^17.0": found 18.2.0

I am already using react in the project (hence it found 18.2.0), so I can't just install it a second time.

I looked into creating aliases, but this won't help me because in my dependencies, react is imported just as react - no way to change this to react-latest or similar. I then tried my luck with pnpm overrides.

This field allows you to instruct pnpm to override any dependency in the dependency graph. This is useful to enforce all your packages to use a single version of a dependency, backport a fix, or replace a dependency with a fork.

I tried it like this in my package.json:

"pnpm": {
  "overrides": {
    "react": "18.2.0"
  }
}

I was hoping this would be a clean way to deal with this, but the warning is still show. Seems like my last chance is accepting it and adding strict-peer-dependencies=false to my .npmrc to stop this to fail the install process. But is there maybe a cleaner way to deal with this?

like image 460
Sven Avatar asked Oct 17 '25 14:10

Sven


1 Answers

The response can be found in the aliases documentation:

pnpm add lodash1@npm:lodash@1
pnpm add lodash2@npm:lodash@2

will install lodash v1 and v2 which you can reference in your code as lodash1 and lodash2.

like image 155
Batato Avatar answered Oct 19 '25 08:10

Batato



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!