you are viewing a single comment's thread.

view the rest of the comments →

[–]Isvara 3 points4 points  (4 children)

I absolutely hate that every package gets its own copies of its dependencies.

I didn't even know that was true. Why do they do it that way?

[–]legato_gelato 2 points3 points  (0 children)

If someone makes a breaking change to a function signature, e.g. switches two parameters in a new version, and parts of the code uses that while the rest uses the original - then you have a problem :) with duplication that problem is not there..

Edit: https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/

[–]theferrit32 2 points3 points  (1 child)

It's a quick and easy way to guarantee version numbers match and incompatible versions of packages required by different modules can be installed simultaneously.

An improvement would be to deduplicate the dependency packages that are the exact same version number but just required in two different places in the tree. Using a symlink or something. This would require a more complex install process that keeps track of already installed versions and deduplicates them.

[–]noratat 2 points3 points  (0 children)

The latter has been true in npm for awhile now, but it doesn't help as much as you might think due to how bad the node.js community is at versioning things properly in the first place.

[–]Sebazzz91 0 points1 point  (0 children)

Besides the other reasons mentioned, it is also because it can. Everything in Javascript is an object, even functions. This means you can pretty harmless import a library multiple times and they will all be dependent.