Search This Blog

2024/03/19

Node.js: npm dedupe

 npm dedupe Searches the local package tree and attempts to simplify

the overall structure by moving dependencies further up
the tree, where they can be more effectively shared by
multiple dependent packages.

For example, consider this dependency graph:

a
+-- b <-- depends on c@1.0.x
| `-- c@1.0.3
`-- d <-- depends on c@~1.0.9
`-- c@1.0.10
In this case, npm dedupe will transform the tree to:

a
+-- b
+-- d
`-- c@1.0.10

Because of the hierarchical nature of node's module lookup,
b and d will both get their dependency met by the single c
package at the root level of the tree.


To prefer deduplication over novelty during the installation process,
run

npm install --prefer-dedupe
or
npm config set prefer-dedupe true.


Note that this operation transforms the dependency tree,
but will never result in new modules being installed.

Using npm find-dupes will run the command in --dry-run mode.

No comments:

Post a Comment