What are Peer Dependencies?

Card Puncher Data Processing

About

Peer Dependencies is a dependency relationship indicating that the dependencies should be provided by parent in the dependency tree.

They are provided by the parent. ie

  • a framework (Jquery, …)
  • the HTML page
  • the root of a monorepo

It indicates that:

  • your (module|package) cannot be used without this dependency.
  • the parent dependency should provide this dependency
  • the dependency will not be available in the distributed artifact.

Example

They model a parent-child relationship

  • Plugin (for the parent, for instance, the jQuery framework)
  • Workspace (for the root parent of the mono repo)
  • Page (where the page provide the peer dependencies)

Management

Javascript

In Javascript Package - Package.json, they are declared in the peerDependencies property of the package.json file.

  • You can add them also at the command line with your package manager. Example: yarn:
yarn add [package] --peer

Bundler - You may have to change the configuration of your bundler to exclude them. Example webpack





Discover More
Javascript Package - Dependency

package Dependency in Node. Dependency are declared/added in package.json: with a package manager or manually - dependency in the code used to build the dependency graph. - build and test...
Javascript Package - Package.json

Package.json is used by npm to store metadata for projects published as package. The package.json files: * serves as documentation for what packages your project depends on. * allows you to specify...
WebPack - Dependency

in WebPack To exclude a package with webpack, you have to: declare it as peerDependency) to define its corresponding global Example with JQuery that is available on the global variable...
Card Puncher Data Processing
What are the kinds of dependency relationships?

This article lists the relationship that you can find between dependency in dependency tree. direct: a dependency of your package dev: a dependency needed to develop and build the package transitive:...



Share this page:
Follow us:
Task Runner