-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Peer Dependencies missing in NPM packages #37264
Comments
Some of the issues listed are surprising. I can see why Yarn complains about Redux: gutenberg/packages/data/package.json Lines 44 to 46 in 1841005
It's listed as a peer dependency and I don't remember why it isn't set as a regular dependency. It feels like it should be a regular dependency. React and React DOM shouldn't be listed there because they are dependencies of gutenberg/packages/element/package.json Lines 36 to 37 in ee14897
Unless the 3rd party libraries define different ranges for React and React DOM. I need to investigate |
Opened PR that should address the issue for |
@youknowriad or @jsnajdr, do you know why we have
We don't even define |
I guess the reasoning is that when you use the data module, you don't necessarily use redux-based stores but that reasoning is a bit flawed to be honest as we'll be using redux in 80% of the time (if not more). Anyway, this was also one of the issues (among other missing dependencies) that were highlighted by attempting to move to pnpm in #37324 :) |
This is a mistake introduced in #21313. Look at this discussion thread: It was proposed to set
In |
Thank you, that explains everything. It's an obvious mistake that needs to be addressed according to your explanation 👍 |
I opened #37364 to fix the issues with |
@diegohaz or @ciampo, do you know why gutenberg/packages/components/package.json Lines 71 to 73 in d6ec4d1
I don't see any reference in the code other than in code comments next to TypeScript types. |
I think we've forgotten to remove it after a refactor. We shouldn't depend on that package. |
I opened #37369 to fix the issue with @jonshipman, I think I addressed most of the issues from the list you shared. The biggest remaining question is whether we can do anything about reports for |
Thanks for working on this; I also should have raised an issue several months ago! As a work-around, we have a significant number of overrides in our |
Thanks for sharing @noahtallen. It pretty much aligns with what @jonshipman reported. I expect that most of the issues are resolved with all the recent changes included. The only thing that bothers me here is React dependencies. It raises the question of whether we should declare it as a peer dependency using "^17.0.0" range in every package that uses any external React library and accesses it directly. I must admit that those checks are very strict because the dependency is satisfied through |
Logically, any package accessed directly by the files of a package should be declared as a dependency of that package, right? By definition, accessing exports from |
@ZebulanStanphill, I think that reasoning makes sense. It's a bit unfortunate that we have to track down peer dependencies of dependencies and repeat them in our packages, but maybe it's worth the hassle. I published to npm a development version of npm packages. It should allow us to test all the latest improvements applied to WordPress packages. A good example would be installing
The stable version should be available in the second half of January. |
Yes, there are some consistency rules that all packages should satisfy. If a package does
And the Depending on
For the same reason as above, The second rule, enforced especially by newer versions of Yarn, is that when a package depends on a package with a peer dependency, it must either satisfy it, or redeclare it explicitly itself. You must do either this:
or this:
but this alone won't do:
The argument why it's not sufficient is rather complex and is described by the Yarn maintainer in this post. |
@jsnajdr, thanks for a detailed summary of how Yarn approaches the problem. It's a bit unfortunate that we need to put extra care here, but it's manageable. Let's put |
Hopefully, the last PR #37578 for |
Description
Yarn 2 (Cherry) implements Plug'n'Play versus the node_modules node linker. One major issue that I have noticed is many packages inside gutenberg are missing peerDependencies on several libraries. This is frequently react, react-dom, or redux. In a traditional npm or yarn 1 environment this is a non-issue as the library will be present in the node_modules folder.
Potential solutions:
Below is a small list provided as an example listed from running yarn when pnp is configured as a nodeLinker.
This list is not extensive. As an example, line 1 could be fixed by adding 'react' to the peerDependencies of the @wordpress/block-editor package. Alternatively, since react is a dependency of @wordpress/element - all the packages could list that as a peerDependency that are missing react or react-dom.
Step-by-step reproduction instructions
Create a new yarn cherry project and require any of the above listed components (@wordpress/components for example).
yarn init -2 -y
yarn install
yarn add -D @wordpress/components
yarn
The screen should relay which dependencies are missing for @wordpress/components. These warnings prevent building and start scripts from executing.
For more details on Yarn and its installation, visit https://yarnpkg.com/getting-started/install
Screenshots, screen recording, code snippet
No response
Environment info
yarn@3.1.1
node@16.2.0
This issue specifically addresses the NPM packages inside gutenberg/packages.
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: