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

[Bug]: Explaining peer warning gives incorrect advice #6203

Open
1 task done
clemyan opened this issue Apr 3, 2024 · 2 comments · May be fixed by #6205
Open
1 task done

[Bug]: Explaining peer warning gives incorrect advice #6203

clemyan opened this issue Apr 3, 2024 · 2 comments · May be fixed by #6205
Labels
bug Something isn't working reproducible This issue can be successfully reproduced

Comments

@clemyan
Copy link
Contributor

clemyan commented Apr 3, 2024

Self-service

  • I'd be willing to implement a fix

Describe the bug

Sometimes, due to how they are aggregated, yarn explain peer-requirements says peer requests cannot be all satisfied when they can.

Consider this dependency tree:

A --> X ==> P@^2
  --> P@1.0.0

B --> Y ==> P@^3
  --> P@1.0.0

where A and B are workspaces , --> represents a regular dependency, and ==> represents a peer dependency.

When we install this, we get an peer warning, which, when explained, gives

$ yarn explain peer-requirements p6ab7e
We have a problem with p, which is provided with version 1.0.0.
It is needed by the following direct dependencies of workspaces in your project:

  ✘ x@npm:1.0.0 [0f866] (via ^2)
  ✘ y@npm:1.0.0 [10ea6] (via ^3)

Unfortunately, put together, we found no single range that can satisfy all those peer requirements.
Your best option may be to try to upgrade some dependencies with yarn up, or silence the warning via logFilters.

However, this advice is not correct as it is easily fixable by making a and b depend on different versions of p.


This is caused by how peer warnings are aggregated by the provided package which loses information on different packages that depend on it. Peer warnings should instead be aggregated by requestee + peer request ident which are the individual knobs that the end user can turn.

To reproduce

const fs = require(`node:fs/promises`);
const p = require(`node:path`);

async function makeWorkspace(path, manifest) {
  await fs.mkdir(path);
  await fs.writeFile(p.join(path, `package.json`), JSON.stringify(manifest));
}

await makeWorkspace(`./package-x`, {
  name: `x`,
  version: `1.0.0`,
  peerDependencies: {
    p: `^2`,
  },
});
await makeWorkspace(`./package-y`, {
  name: `y`,
  version: `1.0.0`,
  peerDependencies: {
    p: `^3`,
  },
});
await makeWorkspace(`./package-p`, {
  name: `p`,
  version: `1.0.0`,
});

await makeWorkspace(`./workspace-a`, {
  name: `a`,
  version: `1.0.0`,
  dependencies: {
    x: `1.0.0`,
    p: `1.0.0`,
  },
});
await makeWorkspace(`./workspace-b`, {
  name: `b`,
  version: `1.0.0`,
  dependencies: {
    y: `1.0.0`,
    p: `1.0.0`,
  },
});

const output = await packageJsonAndInstall({
  workspaces: [
    `workspace-*`,
    `package-*`,
  ],
});
const hash = output.match(/\(p[0-9a-f]{5}\)/)[0].slice(1, -1);

await expect(yarn('explain', 'peer-requirements', hash)).resolves.not.toMatch(/no single range that can satisfy all/);

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
  Binaries:
    Node: 21.7.0 - D:\Users\Clement\AppData\Local\Temp\xfs-cb19a917\node.CMD
    Yarn: 4.1.1 - D:\Users\Clement\AppData\Local\Temp\xfs-cb19a917\yarn.CMD
    npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.15.4 - C:\Program Files\nodejs\pnpm.CMD

Additional context

No response

@clemyan clemyan added the bug Something isn't working label Apr 3, 2024
@yarnbot yarnbot added the reproducible This issue can be successfully reproduced label Apr 3, 2024
@yarnbot

This comment has been minimized.

@clemyan clemyan linked a pull request Apr 4, 2024 that will close this issue
3 tasks
@yarnbot
Copy link
Collaborator

yarnbot commented Apr 25, 2024

This issue reproduces on master:

Error: expect(received).resolves.not.toMatch(expected)

Expected pattern: not /no single range that can satisfy all/
Received string:      "We have a problem with p, which is provided with version 0.0.0-use.local.
It is needed by the following direct dependencies of workspaces in your project:

  ✘ x@workspace:package-x [f8fd9] (via ^2)
  ✘ y@workspace:package-y [b18b8] (via ^3)

Unfortunately, put together, we found no single range that can satisfy all those peer requirements.
Your best option may be to try to upgrade some dependencies with yarn up, or silence the warning via logFilters.
"
    at Object.toMatch (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-9b3e8262b0.zip/node_modules/expect/build/index.js:202:20)
    at module.exports (evalmachine.<anonymous>:54:71)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-69609f7d06.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-69609f7d06.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-69609f7d06.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-69609f7d06.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-312910c71e.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-312910c71e.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-312910c71e.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible This issue can be successfully reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants