-
Notifications
You must be signed in to change notification settings - Fork 17
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
Replace direct with peer dependency on moment.js #46
Comments
See commit message at react-moment-proptypes#7924af433. It was removed at one point, but was leading to other problems due to how the peer dependencies function (see the above link for details there). Ultimately there shouldn't be a problem with two packages in the bundle since the If you have a specific version of NPM (or other package manager) that is pulling multiple versions of the package, would you mind describing the setup and version? |
My issue is not related to dependency management in the sense of installation or version of npm/yarn. It's related to how this library is bundled together with moment.js. Because of that, if you have a web-app, and you compile your bundle with webpack (for example), and you depend on both In my opinion a wrapper library such as this one that augments functionality of a certain library should not be bundled together with said library. That's why peer dependencies exist, to avoid the issue. As for actually installing and working on this repo, what is common practice is to specify a devDependency (instead of a direct one) along with a peerDependency. When you work on the repo you install it, but when you ship it to npm the code requires consumers to provide their own version of This pattern is very common in libraries that depend on React, for example, because having two instances of React in a web-app is a real issue and the React maintainers actually check that you cannot load two Reacts in a single bundle. This has led to an enforcement of the pattern that I have just described. |
A couple questions and points to clarify and see if I'm understanding the problem here. If any of this is incorrect please point it out so I can get a better grasp here. ClarificationsDepedenciesI'm not bundling any dependency with this library. You would see the usage of bundledDependencies if that was the case.
This is not how peerDependencies are intended to be used and let to the original removal and re-adding to dependencies. They are a description of optional dependencies in the form of compatibility to allow the dependency manager to pull in a compatible version of the lib if it has a dependency. This library has a required dependency on The usage of The pattern you link in Bundling
The bundling software will only include multiple versions of Example package-lock.json when installing just {
"name": "react-moment-proptypes_46",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"moment": {
"version": "2.22.2",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz",
"integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y="
},
"react-moment-proptypes": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/react-moment-proptypes/-/react-moment-proptypes-1.6.0.tgz",
"integrity": "sha512-4h7EuhDMTzQqZ+02KUUO+AVA7PqhbD88yXB740nFpNDyDS/bj9jiPyn2rwr9sa8oDyaE1ByFN9+t5XPyPTmN6g==",
"requires": {
"moment": "2.22.2"
}
}
}
} When you bundle this with Webpack you only get the one webpack bundle analyzerI created a gist with a simple Webpack bundle and direct install of Even the analyzer only shows 1 included. From the images you include above I also only see 1 moment included. If you have 2 versions installed you see something different: Questions
|
I'm directly depending on I can build a repo with a minimal reproduction if you think my explanation is not enough. |
It's a failure on my side to correctly describe the case: this library directly depends on I'm well aware of the fact that module bundlers can and do de-duplication of packages, but in my scenario, described above, webpack cannot do that since I depend on an older version. I believe this could have been avoided, but if you think otherwise, I'll probably just upgrade my version of |
The use-case as you describe should only have one reference to If you have following dependencies {
"moment": "2.21.0",
"react-moment-proptypes": "^1.6.0",
} you will end up with a single reference to
I'm not sure what you mean by this. This library depends on moment >= 1.6.0 which should allow for the reduction of included moment.js references to a single package (the directly referenced one). I don't see how it's possible for I really do want to understand what's going on here. CorrectionI wasn't aware that the term |
No worries, I'll create a repo and try to reproduce. It is entirely possible my problem isn't caused by this library, hope I don't sound too angry over the Internet 😄 I'll ping you when it's up. |
|
In response to Jannik's comment: You can read the above discussion about the purposes of dependencies and peer-dependencies. Forcing a change in how something is configured to appease a particular application configuration is not something I see as add-value and actually induces more work for a common user. As for your specific problem, depending on the bundling tool you are using, you should be able to strip out dependencies as part of the bundle configuration. |
This library depends on moment.js both as a direct dependency and as a peer dependency. Because react-dates has picked this library up a consuming application will end up with two moment.js packages in its bundle.
I don't see a reason why moment.js needs to be both a direct and a peer dependency in this library, but maybe I'm missing something, I'd love to clarify that.
If it's just an oversight I'll be glad to contribute a PR to remove moment.js from the direct dependency list and just leave it as a peer dependency.
The text was updated successfully, but these errors were encountered: