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

An aliased package causes an unsolvable peer dependency warning #4301

Closed
octogonz opened this issue Feb 5, 2022 · 3 comments
Closed

An aliased package causes an unsolvable peer dependency warning #4301

octogonz opened this issue Feb 5, 2022 · 3 comments
Milestone

Comments

@octogonz
Copy link
Member

octogonz commented Feb 5, 2022

pnpm version: 6.29.1

Code to reproduce the issue:

  1. Create a package.json file:
{
  "name": "repro1",
  "version": "1.0.0",
  "dependencies": {
    "webpack5": "npm:webpack@~5.68.0"
  }
}
  1. Run pnpm install

Expected behavior:

It should install without errors. (Because if we did "webpack": "~5.68.0" instead, it would install without errors.)

Actual behavior:

 WARN  Issues with peer dependencies found
.
└─┬ webpack
  └─┬ terser-webpack-plugin
    └── ✕ missing peer webpack@^5.1.0
Peer dependencies that should be installed:
  webpack@^5.1.0

The problem is that terser-webpack-plugin has a peer dependency on webpack which is normally satisfied by webpack. But webpack has been renamed to webpack5, so PNPM's validation considers the dependency to be unsatisfied.

More details

In our case, the reason for aliasing the package is that we're developing a plugin that targets both Webpack 4 and Webpack 5:

{
  "name": "repro2",
  "version": "1.0.0",
  "peerDependencies": {
    "@types/webpack": "^4.39.8",
    "webpack": "^5.35.1"
  },
  "peerDependenciesMeta": {
    "@types/webpack": {
      "optional": true
    },
    "webpack": {
      "optional": true
    }
  },
  "devDependencies": {
    "@types/webpack": "4.41.24",
    "webpack5": "npm:webpack@~5.68.0",
    . . .
  }
}

Questions:

  1. With PNPM's installation strategy, is it even possible to create symlinks that would enable terser-webpack-plugin's peer to be satisfied by the webpack5 alias? I'm not sure whether this is solvable. (?)
  2. If it's not solvable, maybe PNPM's validation should ignore this edge case?

Additional information:

  • node -v prints: 14.17.0
  • Windows, macOS, or Linux?: Windows
@zkochan
Copy link
Member

zkochan commented Feb 7, 2022

If this works with Yarn and/or npm (when --legacy-peers are used), then it we should make it work with pnpm as well.

@RexSkz
Copy link
Contributor

RexSkz commented Jan 9, 2023

I think this issue may become more necessary with the complexity of frontend projects grows.

If a project becomes too large and we want to upgrade a dependency (maybe a component library) by page, it's necessary to have different versions of one package, such as:

# old version
pnpm i my-library@1
# old version, which has a peer dependency my-library
pnpm i my-hoc-library@1

# new version
pnpm i my-library-next@npm:my-library@2
pnpm i my-hoc-library-next@npm:my-hoc-library@2

In PNPM, it will print these errors, even if my-hoc-library@2 has a peer dependency my-library@2:

.
└─┬ my-hoc-library 2.0.0
  └── ✕ unmet peer my-library@2.0.0: found 1.0.0

And PNPM also generates the wrong content in .pnpm - a package my-library@4 in my-hoc-library@5.

A temporary way to fix

Currently I can fix my project by manually editing pnpm-lock.yaml and executing pnpm i:

  packages:
    /my-hoc-library/2.0.0-xxxxxx:
      dependencies:
-       my-library: 1.0.0
+       my-library: /my-library/2.0.0-xxxxxx

But this can be hard if the dependency graph is complex. 😢

RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 15, 2023
RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 15, 2023
RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 15, 2023
RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 15, 2023
RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 16, 2023
RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 16, 2023
RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 17, 2023
RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 17, 2023
RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 17, 2023
@RexSkz
Copy link
Contributor

RexSkz commented Mar 18, 2023

PR #6220 should resolve this issue.

In PNPM 7.29.3:

image

After the PR:

image

This should be considered a breaking change because it changes the way PNPM resolves peer dependencies and generate the node_modules.

zkochan pushed a commit that referenced this issue Mar 18, 2023
RexSkz added a commit to RexSkz/pnpm that referenced this issue Mar 19, 2023
zkochan pushed a commit that referenced this issue Mar 22, 2023
close #4301
Co-authored-by: Zoltan Kochan <z@kochan.io>
@zkochan zkochan added this to the v7.30 milestone Mar 23, 2023
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

3 participants