DEV Community

Discussion on: The difference between dependencies and devDependencies in a JavaScript project

Collapse
 
joelnet profile image
JavaScript Joel

There is also a lesser known peerDependency section for creators of libraries!

peerDependency is useful when your library requires an upstream application to have a dependency installed.

An example is if you create a React component. You do not want to specify the dependency in the dependency section. It is possible this may create conflicts in the App. So instead you use the peerDependency section. This will tell the installer "Hey, this also needs React to work!"

Other use-cases of peerDependency is if a library is optional. For example, if I am writing a library that outputs some text to the console, I might check to see if colors is installed. If so, I will colorize the text, if not, then It'll just be black and white. It's up to the upstream application to install the dependency.

Cheers!

Collapse
 
clairecodes profile image
Claire Parker-Jones

Thanks for sharing, that's really useful!