Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm node_modules not being properly nested?

Tags:

npm

I'm getting unexpected behavior when using npm. For example when installing express with the command:

npm install express

I would expect that a folder named, "express" would be created in the "node_modules" directory and that it's dependencies would be installed within a "node_modules" sub-directory within this folder.

What I am seeing is that the "express" folder is being created but all of it's dependencies are being added to the root "node_modules" directory (same level as express) in my project folder and not nested within the "express" folder.

Why is this happening? (using npm v3.3.5)

like image 921
masterwok Avatar asked Oct 03 '15 18:10

masterwok


Video Answer


1 Answers

It's a design change for npm@3, it deduplicates by default. See:

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.

https://github.com/npm/npm/blob/ff47bc138e877835f1c0f419fea5f5672110678a/CHANGELOG.md#flat-flat-flat

https://github.com/npm/npm/issues/6912

like image 138
JMM Avatar answered Jan 05 '23 03:01

JMM