11cb0ef41Sopenharmony_ci---
21cb0ef41Sopenharmony_cititle: npm-dedupe
31cb0ef41Sopenharmony_cisection: 1
41cb0ef41Sopenharmony_cidescription: Reduce duplication in the package tree
51cb0ef41Sopenharmony_ci---
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci### Synopsis
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci```bash
101cb0ef41Sopenharmony_cinpm dedupe
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cialias: ddp
131cb0ef41Sopenharmony_ci```
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci### Description
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciSearches the local package tree and attempts to simplify the overall
181cb0ef41Sopenharmony_cistructure by moving dependencies further up the tree, where they can
191cb0ef41Sopenharmony_cibe more effectively shared by multiple dependent packages.
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciFor example, consider this dependency graph:
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci```
241cb0ef41Sopenharmony_cia
251cb0ef41Sopenharmony_ci+-- b <-- depends on c@1.0.x
261cb0ef41Sopenharmony_ci|   `-- c@1.0.3
271cb0ef41Sopenharmony_ci`-- d <-- depends on c@~1.0.9
281cb0ef41Sopenharmony_ci    `-- c@1.0.10
291cb0ef41Sopenharmony_ci```
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciIn this case, `npm dedupe` will transform the tree to:
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci```bash
341cb0ef41Sopenharmony_cia
351cb0ef41Sopenharmony_ci+-- b
361cb0ef41Sopenharmony_ci+-- d
371cb0ef41Sopenharmony_ci`-- c@1.0.10
381cb0ef41Sopenharmony_ci```
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ciBecause of the hierarchical nature of node's module lookup, b and d
411cb0ef41Sopenharmony_ciwill both get their dependency met by the single c package at the root
421cb0ef41Sopenharmony_cilevel of the tree.
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ciIn some cases, you may have a dependency graph like this:
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci```
471cb0ef41Sopenharmony_cia
481cb0ef41Sopenharmony_ci+-- b <-- depends on c@1.0.x
491cb0ef41Sopenharmony_ci+-- c@1.0.3
501cb0ef41Sopenharmony_ci`-- d <-- depends on c@1.x
511cb0ef41Sopenharmony_ci    `-- c@1.9.9
521cb0ef41Sopenharmony_ci```
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ciDuring the installation process, the `c@1.0.3` dependency for `b` was
551cb0ef41Sopenharmony_ciplaced in the root of the tree.  Though `d`'s dependency on `c@1.x` could
561cb0ef41Sopenharmony_cihave been satisfied by `c@1.0.3`, the newer `c@1.9.0` dependency was used,
571cb0ef41Sopenharmony_cibecause npm favors updates by default, even when doing so causes
581cb0ef41Sopenharmony_ciduplication.
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ciRunning `npm dedupe` will cause npm to note the duplication and
611cb0ef41Sopenharmony_cire-evaluate, deleting the nested `c` module, because the one in the root is
621cb0ef41Sopenharmony_cisufficient.
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ciTo prefer deduplication over novelty during the installation process, run
651cb0ef41Sopenharmony_ci`npm install --prefer-dedupe` or `npm config set prefer-dedupe true`.
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ciArguments are ignored. Dedupe always acts on the entire tree.
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ciNote that this operation transforms the dependency tree, but will never
701cb0ef41Sopenharmony_ciresult in new modules being installed.
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ciUsing `npm find-dupes` will run the command in `--dry-run` mode.
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ciNote: `npm dedupe` will never update the semver values of direct
751cb0ef41Sopenharmony_cidependencies in your project `package.json`, if you want to update
761cb0ef41Sopenharmony_civalues in `package.json` you can run: `npm update --save` instead.
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci### Configuration
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci#### `install-strategy`
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_ci* Default: "hoisted"
831cb0ef41Sopenharmony_ci* Type: "hoisted", "nested", "shallow", or "linked"
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ciSets the strategy for installing packages in node_modules. hoisted
861cb0ef41Sopenharmony_ci(default): Install non-duplicated in top-level, and duplicated as necessary
871cb0ef41Sopenharmony_ciwithin directory structure. nested: (formerly --legacy-bundling) install in
881cb0ef41Sopenharmony_ciplace, no hoisting. shallow (formerly --global-style) only install direct
891cb0ef41Sopenharmony_cideps at top-level. linked: (experimental) install in node_modules/.store,
901cb0ef41Sopenharmony_cilink in place, unhoisted.
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci#### `legacy-bundling`
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci* Default: false
971cb0ef41Sopenharmony_ci* Type: Boolean
981cb0ef41Sopenharmony_ci* DEPRECATED: This option has been deprecated in favor of
991cb0ef41Sopenharmony_ci  `--install-strategy=nested`
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ciInstead of hoisting package installs in `node_modules`, install packages in
1021cb0ef41Sopenharmony_cithe same manner that they are depended on. This may cause very deep
1031cb0ef41Sopenharmony_cidirectory structures and duplicate package installs as there is no
1041cb0ef41Sopenharmony_cide-duplicating. Sets `--install-strategy=nested`.
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ci#### `global-style`
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ci* Default: false
1111cb0ef41Sopenharmony_ci* Type: Boolean
1121cb0ef41Sopenharmony_ci* DEPRECATED: This option has been deprecated in favor of
1131cb0ef41Sopenharmony_ci  `--install-strategy=shallow`
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ciOnly install direct dependencies in the top level `node_modules`, but hoist
1161cb0ef41Sopenharmony_cion deeper dependencies. Sets `--install-strategy=shallow`.
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_ci#### `strict-peer-deps`
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci* Default: false
1231cb0ef41Sopenharmony_ci* Type: Boolean
1241cb0ef41Sopenharmony_ci
1251cb0ef41Sopenharmony_ciIf set to `true`, and `--legacy-peer-deps` is not set, then _any_
1261cb0ef41Sopenharmony_ciconflicting `peerDependencies` will be treated as an install failure, even
1271cb0ef41Sopenharmony_ciif npm could reasonably guess the appropriate resolution based on non-peer
1281cb0ef41Sopenharmony_cidependency relationships.
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ciBy default, conflicting `peerDependencies` deep in the dependency graph will
1311cb0ef41Sopenharmony_cibe resolved using the nearest non-peer dependency specification, even if
1321cb0ef41Sopenharmony_cidoing so will result in some packages receiving a peer dependency outside
1331cb0ef41Sopenharmony_cithe range set in their package's `peerDependencies` object.
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ciWhen such an override is performed, a warning is printed, explaining the
1361cb0ef41Sopenharmony_ciconflict and the packages involved. If `--strict-peer-deps` is set, then
1371cb0ef41Sopenharmony_cithis warning is treated as a failure.
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci#### `package-lock`
1421cb0ef41Sopenharmony_ci
1431cb0ef41Sopenharmony_ci* Default: true
1441cb0ef41Sopenharmony_ci* Type: Boolean
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_ciIf set to false, then ignore `package-lock.json` files when installing. This
1471cb0ef41Sopenharmony_ciwill also prevent _writing_ `package-lock.json` if `save` is true.
1481cb0ef41Sopenharmony_ci
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci#### `omit`
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_ci* Default: 'dev' if the `NODE_ENV` environment variable is set to
1541cb0ef41Sopenharmony_ci  'production', otherwise empty.
1551cb0ef41Sopenharmony_ci* Type: "dev", "optional", or "peer" (can be set multiple times)
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ciDependency types to omit from the installation tree on disk.
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_ciNote that these dependencies _are_ still resolved and added to the
1601cb0ef41Sopenharmony_ci`package-lock.json` or `npm-shrinkwrap.json` file. They are just not
1611cb0ef41Sopenharmony_ciphysically installed on disk.
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_ciIf a package type appears in both the `--include` and `--omit` lists, then
1641cb0ef41Sopenharmony_ciit will be included.
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ciIf the resulting omit list includes `'dev'`, then the `NODE_ENV` environment
1671cb0ef41Sopenharmony_civariable will be set to `'production'` for all lifecycle scripts.
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci#### `include`
1721cb0ef41Sopenharmony_ci
1731cb0ef41Sopenharmony_ci* Default:
1741cb0ef41Sopenharmony_ci* Type: "prod", "dev", "optional", or "peer" (can be set multiple times)
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ciOption that allows for defining which types of dependencies to install.
1771cb0ef41Sopenharmony_ci
1781cb0ef41Sopenharmony_ciThis is the inverse of `--omit=<type>`.
1791cb0ef41Sopenharmony_ci
1801cb0ef41Sopenharmony_ciDependency types specified in `--include` will not be omitted, regardless of
1811cb0ef41Sopenharmony_cithe order in which omit/include are specified on the command-line.
1821cb0ef41Sopenharmony_ci
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ci
1851cb0ef41Sopenharmony_ci#### `ignore-scripts`
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ci* Default: false
1881cb0ef41Sopenharmony_ci* Type: Boolean
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ciIf true, npm does not run scripts specified in package.json files.
1911cb0ef41Sopenharmony_ci
1921cb0ef41Sopenharmony_ciNote that commands explicitly intended to run a particular script, such as
1931cb0ef41Sopenharmony_ci`npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run-script`
1941cb0ef41Sopenharmony_ciwill still run their intended script if `ignore-scripts` is set, but they
1951cb0ef41Sopenharmony_ciwill *not* run any pre- or post-scripts.
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ci
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ci#### `audit`
2001cb0ef41Sopenharmony_ci
2011cb0ef41Sopenharmony_ci* Default: true
2021cb0ef41Sopenharmony_ci* Type: Boolean
2031cb0ef41Sopenharmony_ci
2041cb0ef41Sopenharmony_ciWhen "true" submit audit reports alongside the current npm command to the
2051cb0ef41Sopenharmony_cidefault registry and all registries configured for scopes. See the
2061cb0ef41Sopenharmony_cidocumentation for [`npm audit`](/commands/npm-audit) for details on what is
2071cb0ef41Sopenharmony_cisubmitted.
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_ci#### `bin-links`
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ci* Default: true
2141cb0ef41Sopenharmony_ci* Type: Boolean
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ciTells npm to create symlinks (or `.cmd` shims on Windows) for package
2171cb0ef41Sopenharmony_ciexecutables.
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ciSet to false to have it not do this. This can be used to work around the
2201cb0ef41Sopenharmony_cifact that some file systems don't support symlinks, even on ostensibly Unix
2211cb0ef41Sopenharmony_cisystems.
2221cb0ef41Sopenharmony_ci
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ci#### `fund`
2261cb0ef41Sopenharmony_ci
2271cb0ef41Sopenharmony_ci* Default: true
2281cb0ef41Sopenharmony_ci* Type: Boolean
2291cb0ef41Sopenharmony_ci
2301cb0ef41Sopenharmony_ciWhen "true" displays the message at the end of each `npm install`
2311cb0ef41Sopenharmony_ciacknowledging the number of dependencies looking for funding. See [`npm
2321cb0ef41Sopenharmony_cifund`](/commands/npm-fund) for details.
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci
2351cb0ef41Sopenharmony_ci
2361cb0ef41Sopenharmony_ci#### `dry-run`
2371cb0ef41Sopenharmony_ci
2381cb0ef41Sopenharmony_ci* Default: false
2391cb0ef41Sopenharmony_ci* Type: Boolean
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ciIndicates that you don't want npm to make any changes and that it should
2421cb0ef41Sopenharmony_cionly report what it would have done. This can be passed into any of the
2431cb0ef41Sopenharmony_cicommands that modify your local installation, eg, `install`, `update`,
2441cb0ef41Sopenharmony_ci`dedupe`, `uninstall`, as well as `pack` and `publish`.
2451cb0ef41Sopenharmony_ci
2461cb0ef41Sopenharmony_ciNote: This is NOT honored by other network related commands, eg `dist-tags`,
2471cb0ef41Sopenharmony_ci`owner`, etc.
2481cb0ef41Sopenharmony_ci
2491cb0ef41Sopenharmony_ci
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_ci#### `workspace`
2521cb0ef41Sopenharmony_ci
2531cb0ef41Sopenharmony_ci* Default:
2541cb0ef41Sopenharmony_ci* Type: String (can be set multiple times)
2551cb0ef41Sopenharmony_ci
2561cb0ef41Sopenharmony_ciEnable running a command in the context of the configured workspaces of the
2571cb0ef41Sopenharmony_cicurrent project while filtering by running only the workspaces defined by
2581cb0ef41Sopenharmony_cithis configuration option.
2591cb0ef41Sopenharmony_ci
2601cb0ef41Sopenharmony_ciValid values for the `workspace` config are either:
2611cb0ef41Sopenharmony_ci
2621cb0ef41Sopenharmony_ci* Workspace names
2631cb0ef41Sopenharmony_ci* Path to a workspace directory
2641cb0ef41Sopenharmony_ci* Path to a parent workspace directory (will result in selecting all
2651cb0ef41Sopenharmony_ci  workspaces within that folder)
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ciWhen set for the `npm init` command, this may be set to the folder of a
2681cb0ef41Sopenharmony_ciworkspace which does not yet exist, to create the folder and set it up as a
2691cb0ef41Sopenharmony_cibrand new workspace within the project.
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ci#### `workspaces`
2741cb0ef41Sopenharmony_ci
2751cb0ef41Sopenharmony_ci* Default: null
2761cb0ef41Sopenharmony_ci* Type: null or Boolean
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_ciSet to true to run the command in the context of **all** configured
2791cb0ef41Sopenharmony_ciworkspaces.
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ciExplicitly setting this to false will cause commands like `install` to
2821cb0ef41Sopenharmony_ciignore workspaces altogether. When not set explicitly:
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ci- Commands that operate on the `node_modules` tree (install, update, etc.)
2851cb0ef41Sopenharmony_ciwill link workspaces into the `node_modules` folder. - Commands that do
2861cb0ef41Sopenharmony_ciother things (test, exec, publish, etc.) will operate on the root project,
2871cb0ef41Sopenharmony_ci_unless_ one or more workspaces are specified in the `workspace` config.
2881cb0ef41Sopenharmony_ci
2891cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
2901cb0ef41Sopenharmony_ci
2911cb0ef41Sopenharmony_ci#### `include-workspace-root`
2921cb0ef41Sopenharmony_ci
2931cb0ef41Sopenharmony_ci* Default: false
2941cb0ef41Sopenharmony_ci* Type: Boolean
2951cb0ef41Sopenharmony_ci
2961cb0ef41Sopenharmony_ciInclude the workspace root when workspaces are enabled for a command.
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ciWhen false, specifying individual workspaces via the `workspace` config, or
2991cb0ef41Sopenharmony_ciall workspaces via the `workspaces` flag, will cause npm to operate only on
3001cb0ef41Sopenharmony_cithe specified workspaces, and not on the root project.
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
3031cb0ef41Sopenharmony_ci
3041cb0ef41Sopenharmony_ci#### `install-links`
3051cb0ef41Sopenharmony_ci
3061cb0ef41Sopenharmony_ci* Default: false
3071cb0ef41Sopenharmony_ci* Type: Boolean
3081cb0ef41Sopenharmony_ci
3091cb0ef41Sopenharmony_ciWhen set file: protocol dependencies will be packed and installed as regular
3101cb0ef41Sopenharmony_cidependencies instead of creating a symlink. This option has no effect on
3111cb0ef41Sopenharmony_ciworkspaces.
3121cb0ef41Sopenharmony_ci
3131cb0ef41Sopenharmony_ci
3141cb0ef41Sopenharmony_ci
3151cb0ef41Sopenharmony_ci### See Also
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ci* [npm find-dupes](/commands/npm-find-dupes)
3181cb0ef41Sopenharmony_ci* [npm ls](/commands/npm-ls)
3191cb0ef41Sopenharmony_ci* [npm update](/commands/npm-update)
3201cb0ef41Sopenharmony_ci* [npm install](/commands/npm-install)
321