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?]: Yarn ignores peerDependencies in workspace package #6364

Closed
1 task
quentez opened this issue Jun 29, 2024 · 5 comments
Closed
1 task

[Bug?]: Yarn ignores peerDependencies in workspace package #6364

quentez opened this issue Jun 29, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@quentez
Copy link

quentez commented Jun 29, 2024

Self-service

  • I'd be willing to implement a fix

Describe the bug

After upgrading from 4.1.1 to 4.3.1 I'm now getting an error that one of the packages in my Yarn workspace is failing to provide a package that a dependency declares as peer.

But I already have that package in the peerDependencies key of my package.json. It's as if Yarn is ignoring that field. Could it be related to the work done by @clemyan in #6205 ?

Here's the error:

➤ YN0002: │ @baqhub/sdk-expo@workspace:packages/lib-sdk-expo doesn't provide expo (p6ba33), requested by expo-secure-store.

And in the package.json for @baqhub/sdk-expo:

"peerDependencies": {
  "expo": "*",
  "react-native": ">=0.60"
}

To reproduce

  1. In a Yarn workspace, add the expo-secure-store to one of the packages.
  2. Add expo as a peer dependency to that package.
  3. When running yarn, get a warning indicating that the package should provide the peer dependency.

Environment

System:
  OS: macOS 15.0
  CPU: (8) arm64 Apple M1
Binaries:
  Node: 22.3.0 - /private/var/folders/k1/b_tdbtrx26x_m0r_hvsldpsm0000gn/T/xfs-71da02d9/node
  Yarn: 4.3.1 - /private/var/folders/k1/b_tdbtrx26x_m0r_hvsldpsm0000gn/T/xfs-71da02d9/yarn
  npm: 10.8.1 - /opt/homebrew/bin/npm

Additional context

No response

@quentez quentez added the bug Something isn't working label Jun 29, 2024
@quentez quentez changed the title [Bug?]: Yarn ignores peerDependencies in workspace package [Bug?]: Yarn ignores peerDependencies in workspace package Jun 29, 2024
@arcanis
Copy link
Member

arcanis commented Jun 29, 2024

A workspace has no parent from its general perspective, so it doesn't provide any peer dependency (until it gets used as a dependency of another package). You need to also list expo/react-native as devDependencies (I guess expo already is?).

@quentez
Copy link
Author

quentez commented Jun 29, 2024

@arcanis Thank you for taking a look at this!

I'm not sure I fully understand your answer though.

I'm not doing anything at the workspace level, it's only within one of the sub-packages. Shouldn't it be enough to specify expo as peerDependency without having to also add it as dependency/devDependency?

(I'm not calling expo directly, I'm only adding it to satisfy the constraint from the expo-secure-store dependency).

@arcanis
Copy link
Member

arcanis commented Jun 29, 2024

Workspaces have two perspectives (sets of dependencies):

  • As dependencies of another workspace
  • As root of the dependency tree (for example when running yarn run from within this workspace's folder)

Even if workspaces depending on @baqhub/sdk-expo declare react-native in their dependencies, the second perspective is still there: if you run a yarn run command from packages/lib-sdk-expo, there will be no "parent package", thus no react-native. That's why listing a peer dependency often means you need a matching dev dependency (we probably should make this clearer).

@quentez
Copy link
Author

quentez commented Jun 29, 2024

That makes sense! I appreciate the thorough explanation 🙇‍♂️
And the solution is quite straightforward as well. Not a bug then!

@TheAsda
Copy link

TheAsda commented Aug 12, 2024

Faced the same issue and could not figure it out for a long time. IMHO yarn run is not the most common usage of a package. Clearer error message or some references in documentation would be so much help. With "add to peers" approach it's easy to make sure you have only one copy of a package in your project. Duplicating dev dependencies can lead to multiple versions of a package is workspaces environment if not careful with dependencies management.

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

No branches or pull requests

3 participants