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

Add information about dependenciesMeta.*.injected #323

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

klingenm
Copy link

When using Workspaces with a log of dependencies, I have encountered many times that a dependency gets duplicated between the packages if the peer dependencies are satisfied differently. Since packages may have optional peer dependencies this is a valid case that should not require the package to be duplicated.

It took a long time to find a solution to the problem since the solution is only documented under the package.json documentation page.

Add short info and link to dependenciesMeta.*.injected under troubleshooting to make it easier to find as it is related to workspaces.
@klingenm klingenm temporarily deployed to deploy September 23, 2022 12:16 Inactive
@zkochan
Copy link
Member

zkochan commented Sep 23, 2022

I think a better solution might be to force single version of that package using overrides.

@klingenm
Copy link
Author

klingenm commented Sep 27, 2022

Problem is that having single versions is not enough.

If you satisfyoptional peer dependencies differently in two packages, the "real" dependency gets duplicated.

Lets say we have two packages in our workspace called A and B. They both depend on external package C, that has two optional dependencies D and E.

Now if A only needs D, B only needs E then C will be duplicated, once with D as a peer dependency and once with E as a peer dependency.

The only way to get around that duplication is to take the sum of all peer dependencies used throughout the workspace and apply them to all who import C.

This example probably would not have any side-effects. But if the peer dependency is in a common lib F, that is imported in A and B we can have a lot of issues if C e.g is @nestjs/core that has a bunch of optional dependencies.

@@ -131,6 +131,14 @@ pnpm cannot guarantee that scripts will be run in topological order if there are

If you see the message `There are cyclic workspace dependencies`, please inspect workspace dependencies declared in `dependencies`, `optionalDependencies` and `devDependencies`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a title to this section. Maybe "## Peer dependencies in a workspace"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants