4

I have a sample package.json for my application,

    dependencies : {
        P1 : “^1.0.0”  // has a peer dependency of p3 v1
        P2 : “^1.0.0”  // has a peer dependency of p3 v2
    }

P1 and P2 has peer dependency on P3, but on deferent versions. (e.g P1 has peer dependency of P3 V1 and P2 has peer dependency of P3 V2 )

(I don’t have access to p1 p2 source code. )

Is there any way to resolve such scenarios is my application’s package.json for not showing warning messages?

subrat
  • 111
  • 7
  • 1
    It would be helpful to know what are P1, P2 and P3, in order for people to help you – Shubham Khatri Mar 22 '18 at 11:08
  • P1, P2 and P3 are totally random packages and what they are is completely irrelevant. OP has 2 random packages that require different versions of another random package. The answer should be package agnostic. – coblr Jul 31 '18 at 16:04

2 Answers2

2

My previous answer failed to realize the difference between dependencies and peer dependencies. For those who may also not realize the difference another answer describes it well:

TL;DR: peerDependencies is for dependencies that are exposed to (and expected to be used by) the consuming code, as opposed to "private" dependencies that are not exposed, and are only an implementation detail.

If P1 and P2 indeed both have peer dependencies on incompatible versions of P3 you will need to either find versions of P1 and P2 with compatible peer dependencies of P3 or abandon the use of either P1 or P2.

-1

UPDATE: This answer is only applicable to regular dependencies, NOT peer dependencies. Please see my new answer for a description of the difference and an answer for the case of P3 being a peer dependency.

I'm guessing you're running an old version of npm. Newer versions of npm should be able to handle multiple versions of the same dependency just fine.

How can I update Node.js and npm to the next versions?

  • -1 This is not useful at all. I have the latest versions and I have 12 warnings for various webpack versions: examples: `@2 || 3`, `@^3.1.0`, `@^2.0.0 || ^3.0.0`, `@2.0.0 || ^3.0.0 || ^4.0.0`. Your answer is only applicable for the question "how do I update node and npm to the next versions?" – coblr Jul 31 '18 at 15:59