Peer Dependencies for npm and Yarn

Peer Dependencies for npm and Yarn

galvarez421galvarez421 Posts: 2Questions: 1Answers: 0

Following up on the discussion in https://github.com/DataTables/Dist-DataTables-Bootstrap/pull/2, I think the DataTables package and related packages (styling, extensions, etc.) should actually be using peer dependencies instead of dependencies for things like jQuery, datatables.net, etc. As described in https://nodejs.org/es/blog/npm/peer-dependencies/, "Even for plugins that do have such direct dependencies, probably due to the host package supplying utility APIs, specifying the dependency in the plugin's package.json would result in a dependency tree with multiple copies of the host package—not what you want." In fact, this is currently a problem due with Yarn's deduping behavior, as described in https://github.com/yarnpkg/yarn/issues/5265, https://github.com/yarnpkg/yarn/issues/3778, etc. I experienced this issue firsthand because Yarn installed and used a second version of jQuery because datatables.net has it listed as a dependency, causing the plugin not to work. Of course, the Yarn deduping behavior is an issue with Yarn itself, but I think it helps to illustrate the main reason why peer dependencies make more sense in this case: the DataTables package itself should not install a version of jQuery because this unnecessarily creates the possibility that the application will use a different version of jQuery than DataTables. As the blog post notes, "I'll leave the subtle failures that come from the plugin using a different Winston API than the main application to your imagination."

Answers

  • allanallan Posts: 61,734Questions: 1Answers: 10,111 Site admin

    Thanks! I agree and have logged a bug in our tracker for this.

    Likely I won't change it for the 1.10.x releases, but I've started work on v2, which will enact this.

    Allan

This discussion has been closed.