Setup:
Given the following points
- my_library makes extensive runtime use of jquery.
- in my_library the jquery required via npm is
^3.3.1
by default (because of security fixes in it). However it is compatible also with jquery >=2.2.0 (but is not specified inpackage.json
, yet) - the my_library is used in a custom_project via npm.
- the custom_project requires also outer_library, that is using different & conflicting jquery versions (e.g. let's say jquery 1.7.3).
- the custom_project_2 instead just requires my_library in
dependencies
.
Problems:
- installing custom_project will provoke duplicate dependencies, messing up jquery for one of the two libraries.
- the jquery version in my_library
dependencies
specifies a suggested version (in order to avoid critical vulnerabilities) but doesn't say anything about which jquery minimum version is compatible with my_library
Eventual solution:
To avoid jquery dependency duplication (1.7.3 for outer_library and 3.3.1 for my_library) I could move my jquery ^3.3.1 from dependencies
to devDependencies
, so I'll get the 3.3.1 on development while it won't be installed on production (npm install --only=prod
) and just jquery 1.7.3 will be installed.
But this:
- doesn't guarantees that my_library will get a compatible jquery version, so my_library could easily break.
- adding
jquery@>=2.2.0
inside my_librarypeerDependencies
will at least raise a WARN asking to resolve the conflict manually installing a specific version in custom_project (even though probably it can't be solved).
- adding
feels wrong to me since jquery is a runtime
dependency
and shouldn't go intodevDependencies
(with unit-testing tools, etc.). In fact jquery won't be installed in the custom_project_2, when installing on production (so my_library will break)
Questions
How can I manage to satisfy both use cases of dependency by my_library?
(A) In case the outer_library would require a jquery compatible with my
peerDependencies
definition (>=2.0.0
), would I STILL need to install jquery manually? Or npm will resolve a common version?(B) Are there cases where
peerDependencies
doesn't complain and doesn't require to install anything manually? (as long as semvers are honoured?)(A) Does it make sense to put a dependency like jquery (high probability of conflicts) either inside
peerDependencies
(with an as loose as possible semver) and insidedependencies
with the recommended version?(B) Would that work correctly in every setup and with NPM version
<3
(peerDependencies automatically installed) and>=3
(manual installation needed)?
Appreciated if you can answer even to a part of the questions