node.jsreactjsnpmnpm-installpeer-dependencies

npm - need to automatically install peer dependencies in parent project without ignoring them


Getting below error with upgraded node and npm versions-

enter image description here

Tried solutions:

Everyone is suggesting to use commands to ignore peer dependencies then what is the use of upgrading the versions of npm and node because this was already happening in older versions and we had to manually install peer dependencies?

Can someone please suggest in which npm and node versions peer dependencies can actually be installed automatically without having to ignore them using commands or is there any other solution to fix this error?


Solution

  • Peer dependencies indicate dependencies that have to be explicitly added by the code base that consumes the dependency.

    If you want dependencies of Project-A to be automatically installed when adding Project-A as a dependency in Project-B, they have to be regular dependencies of Project-A, not peer dependencies.

    In somewhat simplified terms, peer dependencies are useful if you have a Project-A and a Project-B to be consumed by a Project-C. Project-A and B both share a dependency and declare it as a peer dependency for Project-C to include, to make sure two versions of the same are not pulled in by A and B into C.