dependencies, peerDependencies, devDependencies

Photo by Hadyn Cutler on Unsplash

devDependencies are the dependencies which are needed for your project during development / release, such as testing libraries like Karma and Jasmine.

I understood better when I read given examples from this link.

Imagine a dependency triangle; where your projectA uses both libraryB and libraryC whereas library B uses libraryC.

Dependencies of projectA:

Dependencies of libraryB:

When projectA and libraryB use different versions of libraryC, some problems may occur; for example, if you expose a class of libraryC as to send it as a parameter to a libraryB method. To warn users or other developers (usually new to the project), it is advised that you add your libraryC to peerDependencies section in your libraryB package.json. Maybe, here I should not use the word “warn” because npm simply does not install and it quits giving error just as below:

Before npm version 7, peerDependencies would not be installed in node_modules (folder of libraryB), you had to install them by placing it in dependencies section and then moving to peerDependencies but after version 7, this case disappears.

If you are not using libraryC in your projectA but you put libraryC in libraryB’s peerDependencies, then libraryB and libraryC (with the version libraryB is using) will be installed at the same level in projectA’s node_modules.

It is up to you to place your dependencies whether in dependencies or peerDependencies. If you don’t want to update your libraryB every time you are updating libraryC for projectA’s needs, then place them in dependencies section.

If you prefer to not to use peerDependencies, you may get an error like this:

This is to warn you to move your common dependencies from dependencies to peerDependencies. Now, we are in a deadlock :) No, just kidding, you can add this config to your ng-package.json file (not package.json) to get rid of this error:

Or, you can add specific package scope names:

After npm install, projectA node_modules will look like this:

Happy Coding!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nil Seri

I would love to change the world, but they won’t give me the source code | coding 👩🏼‍💻 | coffee ☕️ | jazz 🎷 | anime 🐲 | books 📚 | drawing 🎨