[Bug?]: peer dependency no longer guarantees to be the exactly the same one as the one used by the ancestor
envgap__yarnpkg__berry-3135
Original GitHub issue ↗Opened 2021-07-19
01 / FAILURE SIGNATURE
As reported upstream
No identifying execution failure has been captured.
Not checked yet.
- No curated issue-specific recipe or verified environment fix is available.
02 / ENVIRONMENT RECIPE
- Base commit
Not freshly verified- Manifest
package.json- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
yarnpkg/berry #3135 · read the original issue
### Self-service
- [ ] I'd be willing to implement a fix
### Describe the bug
hi!
First of all thanks for all your great work!
I found that after converting few projects to yarn workspaces the behavior of `peerDependencies` has changed: it's no longer guaranteed that used peer dependency in some workspace is exactly the same as in another workspace that consumes the 1st workspace. While [docs](https://yarnpkg.com/advanced/lexicon#peer-dependency) say that they should be the same.
I've tried to add reproduction but messed up with filesystem somewhere. Though I assume it's clear what behavior I expect (if not, please, let me know, I'll do smth about it).
Would be very thankful for any advice.
The final aim: to be able to have different versions of `react` in `a` and `b` workspaces and make `pkg` workspace use exactly the same version of `react` depending on which workspace (`a` or `b`) it's executed.
### To reproduce
``` js repro
const { promises: fs } = require('fs');
await fs.appendFile('.yarnrc.yml', '\nnodeLinker: node-modules\n')
// initializing workspaces
await Promise.all([fs.mkdir('a'), fs.mkdir('b'), fs.mkdir('pkg')]);
await Promise.all([
fs.writeFile('package.json', JSON.stringify({ workspaces: ['a', 'b', 'pkg'] }, null, 2)),
fs.writeFile(
'pkg/package.json',
JSON.stringify(
{
name: 'pkg',
version: '0.0.0',
peerDependencies: {
react: '>16.0.0',
},
},
null,
2,
),
),
fs.writeFile(
'a/package.json',
JSON.stringify(
{
name: 'a',
dependencies: {
pkg: '0.0.0',
react: '16.8.0',
},
},
null,
2,
),
),
fs.writeFile(
'b/package.json',
JSON.stringify(
{
name: 'b',
dependencies: {
pkg: '0.0.0',
react: '17.0.0',
},
},
null,
2,
),
),
]);
await yarn('install');
// initializing files
await Promise.all([
fs.writeFile(
'pkg/index.js',
'module.exports = { reactVersion: require("react").version }',
),
fs.writeFile(
'a/get-react-version-from-package.js',
`const fs = require('fs');
fs.writeFileSync(__dirname + "/react-version.txt", require("pkg").reactVersion)`,
),
fs.writeFile(
'b/get-react-version-from-package.js',
`const fs = require('fs');
fs.writeFileSync(__dirname + "/react-version.txt", require("pkg").reactVersion)`,
),
]);
// running the files
await Promise.all([
yarn('node', 'a/get-react-version-from-package.js'),
yarn('node', 'b/get-react-version-from-packag04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]
Issue-specific recipe and runtime smoke command require review against the complete issue and repository.
Legacy reproduction is generic install-only; match the actual issue failure before admission.