NPM-DEDUPE(1)

πŸŽ€ NAME πŸŽ€

okay bestie, welcome to the NPM-DEDUPE(1) manual page πŸ’… β€” the one and only

npm-dedupe β€” Reduce duplication in the package tree 🌈

✨ Synopsis ✨

npm dedupe

alias: ddp


🌸 Description 🌸

So what does it do? It searches your local package tree and tries to simplify the whole vibe by moving dependencies further up the tree 🌳 β€” like, up to where multiple dependent packages can actually share them properly. It's giving "stop paying rent twice for the same apartment" energy fr fr.

For example, picture 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 into:

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

Why does this slay? Because node's module lookup is hierarchical by nature 🧚 β€” so b and d will both get their dependency met by that single c package chilling at the root level of the tree. One c, two happy dependents, zero drama πŸ‘‘

In some cases, you may have a dependency graph like this:

a
+-- b <-- depends on c@1.0.x
+-- c@1.0.3
`-- d <-- depends on c@1.x
    `-- c@1.9.9

So here's the tea β˜• During the installation process, the c@1.0.3 dependency for b was placed in the root of the tree. And yes, d's dependency on c@1.x could have been satisfied by c@1.0.3 β€” but nah, the newer c@1.9.9 dependency was used instead, because npm favors updates by default, even when doing so causes duplication 😭 (yes, even then. iconic behavior, honestly).

Running npm dedupe will cause npm to note the duplication and re-evaluate, deleting the nested c module β€” because the one in the root is sufficient. Bye bye duplicate, you will not be missed 🫢

Wanna prefer deduplication over novelty during the installation process? Run npm install --prefer-dedupe or npm config set prefer-dedupe true ✨

Arguments are ignored. Dedupe always acts on the entire tree. Like, the whole tree. No cherry-picking, bestie πŸ™ˆ

Also note that this operation transforms the dependency tree, but will never result in new modules being installed. It reshuffles, it doesn't shop πŸ›οΈ

Using npm find-dupes will run the command in --dry-run mode πŸ‘€

Note: npm dedupe will never update the semver values of direct dependencies in your project package.json. If you actually want to update values in package.json, run npm update --save instead. Different tool, different job πŸ’–

πŸ’… Configuration πŸ’…

install-strategy

  • Default: "hoisted"
  • Type: "hoisted", "nested", "shallow", or "linked"

Sets the strategy for installing packages in node_modules πŸ‘‘ Here's the breakdown:

  • hoisted (the default): install non-duplicated in top-level, and duplicated as necessary within directory structure.
  • nested: (formerly --legacy-bundling) install in place, no hoisting.
  • shallow: (formerly --global-style) only install direct deps at top-level.
  • linked: install in node_modules/.store, link in place, unhoisted.

We recommend that package authors use --install-strategy=linked during development to catch undeclared ("phantom") dependencies before publishing πŸ¦‹ β€” because the isolated layout only exposes a package's declared dependencies, so an import of a package that was never added to package.json can fail instead of resolving by accident and shipping broken. That's a whole embarrassing main character moment you do not want at publish time, ngl. See Catching undeclared ("phantom") dependencies ⟨/using-npm/developers#catching-undeclared-phantom-dependencies⟩.

legacy-bundling

  • Default: false
  • Type: Boolean
  • DEPRECATED: This option has been deprecated in favor of --install-strategy=nested

Instead of hoisting package installs in node_modules, install packages in the same manner that they are depended on πŸ₯² Heads up though: this may cause very deep directory structures and duplicate package installs, since there is no de-duplicating. Sets --install-strategy=nested.

global-style

  • Default: false
  • Type: Boolean
  • DEPRECATED: This option has been deprecated in favor of --install-strategy=shallow

Only install direct dependencies in the top level node_modules, but hoist on deeper dependencies. Sets --install-strategy=shallow ✨

strict-peer-deps

  • Default: false
  • Type: Boolean

If set to true, and --legacy-peer-deps is not set, then any conflicting peerDependencies will be treated as an install failure β€” even if npm could reasonably guess the appropriate resolution based on non-peer dependency relationships πŸ’€

By default, conflicting peerDependencies deep in the dependency graph will be resolved using the nearest non-peer dependency specification, even if doing so will result in some packages receiving a peer dependency outside the range set in their package's peerDependencies object.

When such an override is performed, a warning is printed, explaining the conflict and the packages involved πŸ“’ If --strict-peer-deps is set, then this warning is treated as a failure. So like, warning says πŸ‘‹, failure says πŸ’€.

package-lock

  • Default: true
  • Type: Boolean

If set to false, then ignore package-lock.json files when installing πŸ™ˆ This will also prevent writing package-lock.json if save is true.

omit

  • Default: 'dev' if the NODE_ENV environment variable is set to 'production'; otherwise, empty.
  • Type: "dev", "optional", or "peer" (can be set multiple times)

Dependency types to omit from the installation tree on disk πŸ“

Note that these dependencies are still resolved and added to the package-lock.json file β€” they are just not physically installed on disk. It's giving "on the list but not in the room" energy.

If a package type appears in both the --include and --omit lists, then it will be included. Include wins, periodt.

If the resulting omit list includes 'dev', then the NODE_ENV environment variable will be set to 'production' for all lifecycle scripts 🌈

include

  • Default:
  • Type: "prod", "dev", "optional", or "peer" (can be set multiple times)

Option that allows for defining which types of dependencies to install πŸ’–

This is the inverse of --omit=<type>.

Dependency types specified in --include will not be omitted, regardless of the order in which omit/include are specified on the command-line. Order truly does not matter here, bestie ✨

ignore-scripts

  • Default: false
  • Type: Boolean

If true, npm does not run scripts specified in package.json files πŸ™…β€β™€οΈ

Note that commands explicitly intended to run a particular script β€” such as npm start, npm stop, npm restart, npm test, and npm run β€” will still run their intended script if ignore-scripts is set, but they will not run any pre- or post-scripts.

Setting ignore-scripts also disables .npm-extension execution, as if ignore-extension were set 🧚

allow-directory

  • Default: "all"
  • Type: "all", "none", or "root"

Limits the ability for npm to install dependencies from directories πŸ—‚οΈ That is, dependencies that point to a directory instead of a version or semver range. Please note that this could leave your tree incomplete and some packages may not function as intended or designed 😭 Changing this setting will not remove dependencies that are already installed.

  • all allows any directories to be installed.
  • none prevents any directories from being installed.
  • root only allows directories defined in your project's package.json to be installed.

Also allows directory dependencies to be used for other commands like npm view πŸ‘€

allow-file

  • Default: "all"
  • Type: "all", "none", or "root"

Limits the ability for npm to install dependencies from tarball files πŸ“¦ That is, dependencies that point to a local tarball file instead of a version or semver range. Please note that this could leave your tree incomplete and some packages may not function as intended or designed 😭 Changing this setting will not remove dependencies that are already installed.

  • all allows any tarball file to be installed.
  • none prevents any tarball file from being installed.
  • root only allows tarball files defined in your project's package.json to be installed.

Also allows tarball file dependencies to be used for other commands like npm view πŸ‘€

allow-git

  • Default: "none"
  • Type: "all", "none", or "root"

Limits the ability for npm to fetch dependencies from git references 🧡 That is, dependencies that point to a git repo instead of a version or semver range. Please note that this could leave your tree incomplete and some packages may not function as intended or designed 😭 Changing this setting will not remove dependencies that are already installed.

As of npm 12 the default is none. Git dependencies run git against a remote repo and may install configuration the project does not control ⚠️ Opt in explicitly per project (in .npmrc) or per command (on the CLI) when you need git deps.

  • all allows any git dependencies to be fetched and installed.
  • none prevents any git dependencies from being fetched and installed.
  • root only allows git dependencies defined in your project's package.json to be fetched and installed.

Also allows git dependencies to be fetched for other commands like npm view πŸ‘€

allow-remote

  • Default: "none"
  • Type: "all", "none", or "root"

Limits the ability for npm to fetch dependencies from urls 🌐 That is, dependencies that point to a tarball url instead of a version or semver range. Please note that this could leave your tree incomplete and some packages may not function as intended or designed 😭 Changing this setting will not remove dependencies that are already installed.

As of npm 12 the default is none. Tarballs that share a hostname with the configured registry (the typical case for the npm registry, GitHub Packages, and most private registries) are still installed normally 🫢 If your registry serves tarballs from a different host, set replace-registry-host or override this setting. Opt in explicitly per project (in .npmrc) or per command (on the CLI) when you intentionally install from a URL.

  • all allows any url to be installed.
  • none prevents any url from being installed.
  • root only allows urls defined in your project's package.json to be installed.

Also allows url dependencies to be used for other commands like npm view πŸ‘€

audit

  • Default: true
  • Type: Boolean

When "true", submit audit reports alongside the current npm command to the default registry and all registries configured for scopes πŸ›‘οΈ See the documentation for npm help audit for details on what is submitted.

  • Default: true
  • Type: Boolean

Tells npm to create symlinks (or .cmd shims on Windows) for package executables πŸ”—

Set to false to have it not do this. This can be used to work around the fact that some file systems don't support symlinks, even on ostensibly Unix systems 😀 (looking at you, weird filesystems).

fund

  • Default: true
  • Type: Boolean

When "true", displays the message at the end of each npm install acknowledging the number of dependencies looking for funding πŸ’Έ See npm help fund for details. Support your maintainers, bestie, they're literally carrying the ecosystem 🫢

dry-run

  • Default: false
  • Type: Boolean

Indicates that you don't want npm to make any changes and that it should only report what it would have done πŸ‘€ This can be passed into any of the commands that modify your local installation, eg, install, update, dedupe, uninstall, as well as pack and publish. It's the "look but don't touch" of npm commands ✨

🚨 heads up bestie: this one is NOT honored by other network related commands, eg dist-tags, owner, etc. so don't come for me when it doesn't work there πŸ’€

🌸 workspace

  • Default: (nada, zilch, empty)
  • Type: String (and yes, you can set it multiple times πŸ’…)

Okay so this one lets you run a command in the context of the configured workspaces of the current project β€” while filtering so it only runs on the workspaces you pick with this option ✨

Valid values for the workspace config are either:

  • Workspace names πŸ‘‘
  • Path to a workspace directory
  • Path to a parent workspace directory (this one's giving "select all", because it'll pull in every workspace inside that folder 🫢)

Lowkey iconic detail: when it's set for the npm init command, you can point it at the folder of a workspace that doesn't even exist yet β€” and it'll create the folder and set it up as a brand new workspace within the project. main character energy fr 🌈

This value is not exported to the environment for child processes.


πŸ¦‹ workspaces

  • Default: null
  • Type: null or Boolean

Set it to true to run the command in the context of all configured workspaces. Slay.

Explicitly setting this to false will cause commands like install to ignore workspaces altogether. And when you don't set it explicitly, here's the vibe check:

  • Commands that operate on the node_modules tree (install, update, etc.) will link workspaces into the node_modules folder.
  • Commands that do other things (test, exec, publish, etc.) will operate on the root project β€” unless one or more workspaces are specified in the workspace config.

This value is not exported to the environment for child processes.


πŸŽ€ include-workspace-root

  • Default: false
  • Type: Boolean

Include the workspace root when workspaces are enabled for a command. Basically: do you want the root project invited to the party too? πŸ₯³

When false, specifying individual workspaces via the workspace config, or all workspaces via the workspaces flag, will cause npm to operate only on the specified workspaces, and not on the root project. Root stays home, no cap.

This value is not exported to the environment for child processes.


  • Default: false
  • Type: Boolean

When you set this, file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. So like, the real thing instead of a little shortcut pointing at it, ykwim? πŸ”₯

πŸ™ˆ tiny caveat bestie: this option has no effect on workspaces. Zero. None. Don't @ me.

✨ SEE ALSO ✨

  • npm help find-dupes πŸ”
  • npm help ls πŸ“‹
  • npm help update ⬆️
  • npm help install πŸ“¦

and that's the whole page, bestie!! go forth and dedupe responsibly πŸ§šβ€β™€οΈπŸ’–

mwah πŸ’‹ β€” this lil masterpiece is npm@12.2.1, dated October 2026, and stamped NPM-DEDUPE(1) in the corner like a little name tag πŸŽ€

πŸ“¦ where this page comes from