drmrbrewer
drmrbrewer

Reputation: 12989

node_modules structure remains flat even after removing and re-installing

Originally I think that my node_modules folder had one subfolder for each of the packages specified in my package.json file.

Then, some time ago, I think I ran:

$ npm dedupe

to flatten the structure and avoid duplicated packages in node_modules.

But now, the node_modules folder seems to have retained the de-duped structure, even after I go through the following upgrade / uninstall / reinstall process:

$ rm -rf node_modules
$ ncu -a
$ npm install

After this, node_modules is again filled with hundreds of sub-folders, in a flat, de-duped structure.

Not that it matters much (de-duped is fine), but I'm curious to know why it hasn't gone back to the hierarchical structure... maybe there's a setting somewhere I've missed?

Upvotes: 0

Views: 95

Answers (1)

peteb
peteb

Reputation: 19418

This is because your NPM version was upgraded to v3+ at some point after your node_modules was initially setup. Not much you can do now unless you downgrade to NPM v2 or earlier.

NPM v3+ uses a flat dependency structure to reduce package duplication and nesting.

  • Read more about NPM v3 dependency resolution here.

  • Read more about NPM v2 dependency resolution here

Upvotes: 1

Related Questions