Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency deduplication seems not to work #7105

Open
4 tasks done
pmb0 opened this issue Sep 18, 2023 · 6 comments
Open
4 tasks done

Dependency deduplication seems not to work #7105

pmb0 opened this issue Sep 18, 2023 · 6 comments

Comments

@pmb0
Copy link

pmb0 commented Sep 18, 2023

Verify latest release

  • I verified that the issue exists in the latest pnpm release

pnpm version

8.7.6

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

No response

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

https://github.com/pmb0/pnpm-peer-deduplication-not-working/tree/main

Reproduction steps

git clone https://github.com/pmb0/pnpm-peer-deduplication-not-working
pnpm i
pnpm test

Describe the Bug

When using NestJS dependencies in own monorepo libs, @nestjs/core is installed multiple times, which leads to runtime errors in NestJS. pnpm dedupe and dedupe-peer-dependents=true seem to have no effect. This problem occurred in the past but not in pnpm@8.6.0 and after upgrading to any version after 8.6.0 it reappeared.

As far as I know, the problem can only be solved by installing the NestJS dependencies in the root package (resolve-peers-from-workspace-root=true), which is a workaround.

Expected Behavior

NestJS dependencies such as @nestjs/platform-express define their dependencies as follows:

  "devDependencies": {
    "@nestjs/core": "10.2.5"
  },
  "peerDependencies": {
    "@nestjs/core":"^10.0.0"
  }

If my own libs do the same, I expect only one copy of @nestjs/core to exist afterwards.

Which Node.js version are you using?

v18.16.0

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

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

No response

@pmb0 pmb0 added the type: bug label Sep 18, 2023
@gentoo90
Copy link

gentoo90 commented Oct 7, 2023

One more reproduction with PNPM 8.8.0 and nodejs 20.5.1 on Linux:

git clone https://github.com/gentoo90/pnpm-dedupe-bug-repro
pnpm i
pnpm build

It's an empty Angular 16 project with a custom webpack config that uses webpack-manifest-plugin.
It has the same issue with webpack and esbuild that was described in #6153.
As a workaround (in workaround branch) add esbuild to webpack-manifest-plugin peer dependencies via readPackage hook in .pnpmfile.cjs:

function readPackage(pkg, context) {
  if (pkg?.name == 'webpack-manifest-plugin') {
    context.log(`Fixing dependencies of ${pkg.name}`);
    pkg.peerDependencies['esbuild'] = '0.18.17';
  }
  return pkg;
}

module.exports = {
  hooks: {
    readPackage,
  }
};

@pmb0
Copy link
Author

pmb0 commented Nov 1, 2023

I think #7163 is the same issue

@shry
Copy link

shry commented Nov 3, 2023

We do have the same issue in a big NestJS monorepo. A clean install with pnpm@8.6.0 version works fine, newer versions are failing with the deduplication.

@pmb0
Copy link
Author

pmb0 commented Nov 6, 2023

Probably #6605 has reintroduced the problem in pnpm@8.6.1.

@pmb0
Copy link
Author

pmb0 commented Dec 5, 2023

@zkochan is there a chance to get multiple copies of same deps fixed?

@zkochan
Copy link
Member

zkochan commented Jan 29, 2024

This is not high priority right now. You can install @nestjs/microservices and @nestjs/platform-express in the root of the workspace and you'll get a single version of @nestjs/core.

In any case, dedupe-peer-dependents is just a dirty workaround. It symlinks dependencies used by other workspace projects, which breaks isolation between projects. It better to handle it manually as I suggested.

The easiest way to fix this would be probably to use dependencies from any workspace projects, when resolving peer dependencies (not just dependencies of the real dependent workspace project).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants