v3nt
v3nt

Reputation: 2912

Why does installing one npm package add many subfolders in node_modules?

I've updated node / npm which I use with my grunt projects.

However when I now want to add a package to a project myproject/ (say npm install grunt-favicon) it seems to add hundreds of folders to myproject/node_modules/ whereas it only used to add one - normally prefixed with grunt like node_modules/grunt-favicon.

My knowledge of these things is basic but these seem to be required dependencies, and even some of these items have even more dependencies.

Should it not be adding these dependencies somewhere else? If so how to i correct this?

I use npm 3.3.5, node 4.1.1, grunt-cli v0.1.13 and grunt v0.4.5.

And this screenshot shows ~/.npm on the left then ~/myproject/node_modules on the right

~/.npm on the left then

Upvotes: 26

Views: 7559

Answers (1)

mik01aj
mik01aj

Reputation: 12382

This is correct, don't worry. You're still installing the packages locally, just the directory structure looks a bit different. It is a behaviour that changed in npm v3.0.0: now all the dependencies' dependencies are installed directly in the node_modules folder (as far as this doesn't cause version conflicts). This greatly reduces the file tree size.

From npm 3.0.0 release notes:

Flat, flat, flat!

Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's node_modules folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.

Upvotes: 29

Related Questions