Does npm have a flag for automatic installation of peer dependencies?

I’m currently working with React, and whenever I install it via npm, I encounter several warnings about unmet peer dependencies. For instance, after running this command:

npm install --save react
[email protected] /home/user/projects/myapp
├── [email protected]
├── UNMET PEER DEPENDENCY prop-types@^15.6.0
├── UNMET PEER DEPENDENCY react-dom@^17.0.0
├── UNMET PEER DEPENDENCY scheduler@^0.20.2
└── UNMET PEER DEPENDENCY object-assign@^4.1.1

npm WARN [email protected] requires a peer of prop-types@^15.6.0 but none was installed.
npm WARN [email protected] requires a peer of react-dom@^17.0.0 but none was installed.
npm WARN [email protected] requires a peer of scheduler@^0.20.2 but none was installed.
npm WARN [email protected] requires a peer of object-assign@^4.1.1 but none was installed.

I want to avoid having to install each dependency manually like this:

npm install --save [email protected] prop-types@^15.6.0 react-dom@^17.0.0 scheduler@^0.20.2 object-assign@^4.1.1

Is there a built-in command or option in npm that allows for the automatic handling of peer dependencies? It would significantly streamline my process and save me time.

This drove me nuts for years until I automated it. Yeah, the warnings are annoying, but npm keeps them because peer deps can seriously break stuff when versions conflict.

I built a workflow that monitors package installs and auto-handles peer dependencies when someone adds new packages. It reads the requirements, checks for conflicts with existing versions, and installs what’s missing.

For React, it automatically grabs react-dom, prop-types, and other peers. No more manual commands or forgotten deps that break builds later.

It logs everything so you can see what got installed and why. Saves tons of time and kills those “works on my machine” issues when someone forgets peer deps.

Takes about 10 minutes to set up and handles all dependency management automatically. Way better than remembering flags or using third-party tools that might break.

No native npm flag for this, but I’ve hit this wall tons of times. I usually check the package docs first - popular ones like React tell you upfront what peers you need. React almost always needs react-dom unless you’re only doing server-side stuff. Try npm info <package-name> peerDependencies before installing. Shows you what’s required so you can install everything at once instead of dealing with warnings later. Some devs switch to Yarn since it handles peer deps better, but that’s probably overkill. The manual way sucks but at least you learn what your project actually needs.

Currently, npm does not have a built-in flag to automatically install peer dependencies. This design choice is intentional to ensure developers explicitly manage these dependencies, considering they are typically shared across the project and require consistent versioning. I’ve encountered similar challenges with React projects, and I find those warnings beneficial in avoiding potential version conflicts that could disrupt functionality. A practical solution I’ve used is running npm install --save react react-dom simultaneously, as react-dom is commonly needed alongside React. For a more efficient approach, consider using npx install-peerdeps <package-name>, a third-party tool that automates the installation of a package with all its peer dependencies, streamlining the process significantly for larger projects.

just run npm install --legacy-peer-deps when installing packages. it ignores peer dependency warnings and installs everything anyway. not perfect, but works in most cases and beats manually adding each dependency. i’ve used it on react projects without any problems.