Search code examples
javascriptnode.jsbackbone.js

npm not installing the dependencies of top level dependencies


From what i have seen, when a top level dependency such as BackboneJS is installed in a project using npm, it comes with several other hard or soft dependencies required by Backbone (or any other module). I was under the impression that those hard and soft dependencies would be recursively installed into a separate node_modules directory within, in this specific case, the top level Backbone directory.

So for instance, backbone has a hard dependency on underscore. i would expect for underscore to be a subdirectory within the main backbone file, but instead underscore is installed along side backbone in the home directories node modules file.

Im still very iffy on package management and integrating multiple JS modules, so i'm not sure if this even matters but i feel like it does. Im currently following along with O'reillys "full stack web development with Backbone.js" book and the example shows the document tree with underscore as a subdirectory of backbone.

If someone could please clarify whether or not this is actually a problem, or if there is a work around to it that would be greatly appreciated.


Solution

  • It is not a problem at all. It is just how npm works. All dependencies (even dependencies of your dependencies) are installed at the same level. But when you use require('module');, NodeJS will know where to search it so Backbone will be able to find underscore without any problem.