pnpm / pnpm

Fast, disk space efficient package manager
https://pnpm.io
MIT License
29.95k stars 1.02k forks source link

getting wrong peer dependency version #8799

Open unional opened 1 week ago

unional commented 1 week ago

Verify latest release

pnpm version

9.14.2

Which area(s) of pnpm are affected? (leave empty if unsure)

Dependencies resolver

Link to the code that reproduces this issue or a replay of the bug

No response

Reproduction steps

Not able to create a repo yet. As with other dependency resolution issues, this seems to happen in some specific cases.

Describe the Bug

I got this when running pnpm why -r @vitest/browser on a private monorepo

pkg-a

dependencies:
@vitest/coverage-v8 2.1.5
└─┬ vitest 2.1.5 peer
  └── @vitest/browser 2.1.4 peer
vitest 2.1.5
└── @vitest/browser 2.1.4 peer

I have vitest and @vitest/coverage-v8 as peerDependencies in pkg-a.

It shows that @vitest/browser 2.1.4 as peer of vitest 2.1.5. Which is wrong. The package.json in vitest is using exact version 2.1.5:

{
 "name": "vitest",
  "peerDependencies": {
    "@vitest/browser": "2.1.5",
    "@vitest/ui": "2.1.5"
  }
}

I have tried using exact version 2.1.5 and catalog: in pkg-a, both yield the same problem.

Expected Behavior

pnpm should install @vitest/browser 2.1.5.

I have tried deleting node_modules and that doesn't work either. I have to delete the lock file to get it to install 2.1.5.

That explain why I can't create a simple repro.

Which Node.js version are you using?

22.9.0

Which operating systems have you used?

If your OS is a Linux based, which one it is? (Include the version if relevant)

No response

zkochan commented 1 week ago

peer dependencies should be singletons, so it may happen that a different version gets installed and pnpm will print a warning about it. But if adding it to pkg-a doesn't help, then it is an issue.

Using an override will probably help:

{
  "pnpm": {
    "overrides": {
      "@vitest/browser": "2.1.5"
    }
  }
}