Home Ask Login Register

Developers Planet

Your answer is one click away!

rafek February 2016

npm3 does not flatten a dependency structure completely

npm3 brought to use dependencies flattening so that a node_modules folder is flat. Apparently that's not always true. I have my application, let's name it A and a module I'm developing, B. That module has gulp as a dependency and some gulp plugins, like gulp-rename. I was expecting to have gulp and gulp-rename in the node-modules folder of my app A (as it has B as a dependency). But this is not the case. gulp-rename is in fact in A/node_modules but gulp itself is in A/node_modules/B/node_modules folder.

Any clues why is this happening?

UPDATE

I've narrowed down the issue to this particular case:

Having an app A and a module I'm developing, B. That module has gulp as a dependency and a package.json bin property defined as following (B's package.json):

javascript "bin" { "gulp": "<some_valid_path>" }

I was expecting to have gulp in the node-modules folder of my app A (as it has B as a dependency and because of npm3 dependency flattening). But apparently npm leaves it in A/node_modules/B/node_modules folder. Is it an intended behaviour and why?

Answers


Tomas Kulich February 2016

Well, npm flattens your dependency tree as much as possible; this however does not mean it's always entirely flat. For example, if your dependency D1 depends on A ^1.0.0 and D2 depends on A ^2.0.0, npm obviously cannot put both these dependencies to the root node_modules simultaneously. One version of A (say 1.0.0) may go to the root, the other must go to the node_modules/D2/node_modules such that D2 finds A in correct version before it even starts looking for it in a parent dir.

Post Status

Asked in February 2016
Viewed 1,933 times
Voted 5
Answered 1 times

Search




Leave an answer


Quote of the day: live life