Sean Adkinson Sean Adkinson - 4 months ago 14
Node.js Question

NPM installing nested dependency when already satisfied by parent

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
?

Answer

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.