4 ms·
does it mean that if I have 10 modules that depends on exactly the same version of another module (e.g. dependent 1.1.1).. npm will download 1.1.1 10 times? Wou
by miralabs 11y ago
does it mean that if I have 10 modules that depends on exactly the same version of another module (e.g. dependent 1.1.1).. npm will download 1.1.1 10 times? Wouldn't it just use the single package with the correct and share it across? Or the cache is main use to copy the dependent module 10 times.
- AgentME 11y agoThe same version of the same package isn't ever downloaded multiple times. That's cached. Packages may be installed in multiple locations though. NPM doesn't reinstall dependencies that are already above it in the tree. If A depends on B and C, and B depends on (an overlapping version range of) C and D, then B and C will be installed first in A's node_modules directory, and then NPM will install the dependencies of B and C in their own node_modules directories, except that it will avoid installing a copy of C in B's node_modules directory because it already exists in a higher folder. However, if B and C both depend on D, then NPM will install D in each's node_modules folders. You can run `npm prune` (or `npm dedupe`? I can't remember) to make it lift D up a folder so it only needs one copy.
- pluma 11y agoI think `dedupe` is now (i.e. in the most recent version of NPM) part of the install process, actually. So the only situation in which you end up with two copies of the same dependency is if two of your dependencies depend on incompatible versions of the same sub-dependency.