yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.4k stars 2.73k forks source link

Spurious warning in workspace about unmet peer dependency #8933

Open chriscoomber opened 1 year ago

chriscoomber commented 1 year ago

Bug

I'm seeing warning " > my-library@1.0.0" has unmet peer dependency "react@^18.2.0". even though the package which depends on my-library has the react defined in its "dependencies".

my-app's package.json:

{
  "name": "my-app",
  "version": "1.0.0",
  "dependencies": {
    "react": "^18.2.0",
    "my-library": "1.0.0"
  }
}

my-library's package.json:

{
  "name": "my-library",
  "version": "1.0.0",
  "peerDependencies": {
    "react": "^18.2.0"
  }
}

Reproduction

For a simple repro, see here: https://github.com/chriscoomber/yarn-workspace-peer-dependency-repro/

Note that this can be worked around by adding "react": "^18.2.0" to the root package's package.json, however this is not a good solution since that's not how things are supposed to be configured, and it introduces duplication between root's package.json and my-app's package.json.

Versions

% yarn -v
1.22.19
% npm -v
8.5.0

Related issues

There seems to be some related issues, but they seem to be closed many years ago or about something slightly different. For example, #5810 was slightly different as it was talking about dev-dependencies, and also the resolution of this (use yarn 2) is unsatisfactory for me since I use expo, which recommends yarn classic.