1

I'm having an issue with NPM installing two copies of React in my project. Here are the relevant parts of the dependencies:

My package.json:

"dependencies": {
    "react": "0.12.2",
    "tcomb-form": "0.4.5"
}

tcomb-form's package.json:

"peerDependencies": {
    "react": ">=0.12.0"
}

I would not expect tcomb-form to get it's own copy of React, since I already have a dependency that satisfies its peerDependencies.

However, in npm 2.7.4, it does install a separate version in tcomb-form/node_modules/react, and this version is incompatible with my version (I use 0.12, and it is installing 0.13)

In npm 1.4.28, this behavior was different, and tcomb-form/node_modules/react would not exist, and it would just use my version.

Is there anyway to make it so that we all use the same version of React in the latest npm?

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
Sean Adkinson
  • 8,425
  • 3
  • 45
  • 64
  • I did some tests with npm 1.4.28 and 2.8.3 and couldn't reproduce your issue with either. I suspect all the details matter here including perhaps your fully-specified dependencies, peerDependencies, and devDependencies. I don't have the knowledge to say exactly why each version does what. If you can post a [MCVE](http://stackoverflow.com/help/mcve) we might be able to track it down exactly. – Peter Lyons Apr 23 '15 at 20:27

1 Answers1

1

npm dedupe should handle this. In future versions of npm, I believe this will happen during npm install by default, but as of 1.x and 2.x I think a separate dedupe is required.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • Ah, yes, that removed the nested `react`. Unfortunately, now I can't `shrinkwrap` after I `dedupe` because it has moved dependencies around, and doesn't think they should be where it put them. Do you have experience with `shrinkwrap` after a `dedupe`? I'll accept this answer shortly, thank you. – Sean Adkinson Apr 23 '15 at 20:23
  • No, I tried shrinkwrap extensively and finally gave up on it as not viable in npm 1.x and 2.x. I think they are overhauling it for npm 3.x and then it might actually work properly. – Peter Lyons Apr 23 '15 at 20:29
  • Yeah, I've been banging my head against the wall trying to get shrinkwrap to work, and this is my second time trying to do so. For now, looks like I am able to just dedupe react with `npm dedupe react`, and this doesn't touch any other packages, so I'm still able to shrinkwrap afterwards. Thanks for the help. – Sean Adkinson Apr 23 '15 at 20:52