1--- 2title: npm-dedupe 3section: 1 4description: Reduce duplication in the package tree 5--- 6 7### Synopsis 8 9```bash 10npm dedupe 11 12alias: ddp 13``` 14 15### Description 16 17Searches the local package tree and attempts to simplify the overall 18structure by moving dependencies further up the tree, where they can 19be more effectively shared by multiple dependent packages. 20 21For example, consider this dependency graph: 22 23``` 24a 25+-- b <-- depends on c@1.0.x 26| `-- c@1.0.3 27`-- d <-- depends on c@~1.0.9 28 `-- c@1.0.10 29``` 30 31In this case, `npm dedupe` will transform the tree to: 32 33```bash 34a 35+-- b 36+-- d 37`-- c@1.0.10 38``` 39 40Because of the hierarchical nature of node's module lookup, b and d 41will both get their dependency met by the single c package at the root 42level of the tree. 43 44In some cases, you may have a dependency graph like this: 45 46``` 47a 48+-- b <-- depends on c@1.0.x 49+-- c@1.0.3 50`-- d <-- depends on c@1.x 51 `-- c@1.9.9 52``` 53 54During the installation process, the `c@1.0.3` dependency for `b` was 55placed in the root of the tree. Though `d`'s dependency on `c@1.x` could 56have been satisfied by `c@1.0.3`, the newer `c@1.9.0` dependency was used, 57because npm favors updates by default, even when doing so causes 58duplication. 59 60Running `npm dedupe` will cause npm to note the duplication and 61re-evaluate, deleting the nested `c` module, because the one in the root is 62sufficient. 63 64To prefer deduplication over novelty during the installation process, run 65`npm install --prefer-dedupe` or `npm config set prefer-dedupe true`. 66 67Arguments are ignored. Dedupe always acts on the entire tree. 68 69Note that this operation transforms the dependency tree, but will never 70result in new modules being installed. 71 72Using `npm find-dupes` will run the command in `--dry-run` mode. 73 74Note: `npm dedupe` will never update the semver values of direct 75dependencies in your project `package.json`, if you want to update 76values in `package.json` you can run: `npm update --save` instead. 77 78### Configuration 79 80#### `install-strategy` 81 82* Default: "hoisted" 83* Type: "hoisted", "nested", "shallow", or "linked" 84 85Sets the strategy for installing packages in node_modules. hoisted 86(default): Install non-duplicated in top-level, and duplicated as necessary 87within directory structure. nested: (formerly --legacy-bundling) install in 88place, no hoisting. shallow (formerly --global-style) only install direct 89deps at top-level. linked: (experimental) install in node_modules/.store, 90link in place, unhoisted. 91 92 93 94#### `legacy-bundling` 95 96* Default: false 97* Type: Boolean 98* DEPRECATED: This option has been deprecated in favor of 99 `--install-strategy=nested` 100 101Instead of hoisting package installs in `node_modules`, install packages in 102the same manner that they are depended on. This may cause very deep 103directory structures and duplicate package installs as there is no 104de-duplicating. Sets `--install-strategy=nested`. 105 106 107 108#### `global-style` 109 110* Default: false 111* Type: Boolean 112* DEPRECATED: This option has been deprecated in favor of 113 `--install-strategy=shallow` 114 115Only install direct dependencies in the top level `node_modules`, but hoist 116on deeper dependencies. Sets `--install-strategy=shallow`. 117 118 119 120#### `strict-peer-deps` 121 122* Default: false 123* Type: Boolean 124 125If set to `true`, and `--legacy-peer-deps` is not set, then _any_ 126conflicting `peerDependencies` will be treated as an install failure, even 127if npm could reasonably guess the appropriate resolution based on non-peer 128dependency relationships. 129 130By default, conflicting `peerDependencies` deep in the dependency graph will 131be resolved using the nearest non-peer dependency specification, even if 132doing so will result in some packages receiving a peer dependency outside 133the range set in their package's `peerDependencies` object. 134 135When such an override is performed, a warning is printed, explaining the 136conflict and the packages involved. If `--strict-peer-deps` is set, then 137this warning is treated as a failure. 138 139 140 141#### `package-lock` 142 143* Default: true 144* Type: Boolean 145 146If set to false, then ignore `package-lock.json` files when installing. This 147will also prevent _writing_ `package-lock.json` if `save` is true. 148 149 150 151#### `omit` 152 153* Default: 'dev' if the `NODE_ENV` environment variable is set to 154 'production', otherwise empty. 155* Type: "dev", "optional", or "peer" (can be set multiple times) 156 157Dependency types to omit from the installation tree on disk. 158 159Note that these dependencies _are_ still resolved and added to the 160`package-lock.json` or `npm-shrinkwrap.json` file. They are just not 161physically installed on disk. 162 163If a package type appears in both the `--include` and `--omit` lists, then 164it will be included. 165 166If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment 167variable will be set to `'production'` for all lifecycle scripts. 168 169 170 171#### `include` 172 173* Default: 174* Type: "prod", "dev", "optional", or "peer" (can be set multiple times) 175 176Option that allows for defining which types of dependencies to install. 177 178This is the inverse of `--omit=<type>`. 179 180Dependency types specified in `--include` will not be omitted, regardless of 181the order in which omit/include are specified on the command-line. 182 183 184 185#### `ignore-scripts` 186 187* Default: false 188* Type: Boolean 189 190If true, npm does not run scripts specified in package.json files. 191 192Note that commands explicitly intended to run a particular script, such as 193`npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run-script` 194will still run their intended script if `ignore-scripts` is set, but they 195will *not* run any pre- or post-scripts. 196 197 198 199#### `audit` 200 201* Default: true 202* Type: Boolean 203 204When "true" submit audit reports alongside the current npm command to the 205default registry and all registries configured for scopes. See the 206documentation for [`npm audit`](/commands/npm-audit) for details on what is 207submitted. 208 209 210 211#### `bin-links` 212 213* Default: true 214* Type: Boolean 215 216Tells npm to create symlinks (or `.cmd` shims on Windows) for package 217executables. 218 219Set to false to have it not do this. This can be used to work around the 220fact that some file systems don't support symlinks, even on ostensibly Unix 221systems. 222 223 224 225#### `fund` 226 227* Default: true 228* Type: Boolean 229 230When "true" displays the message at the end of each `npm install` 231acknowledging the number of dependencies looking for funding. See [`npm 232fund`](/commands/npm-fund) for details. 233 234 235 236#### `dry-run` 237 238* Default: false 239* Type: Boolean 240 241Indicates that you don't want npm to make any changes and that it should 242only report what it would have done. This can be passed into any of the 243commands that modify your local installation, eg, `install`, `update`, 244`dedupe`, `uninstall`, as well as `pack` and `publish`. 245 246Note: This is NOT honored by other network related commands, eg `dist-tags`, 247`owner`, etc. 248 249 250 251#### `workspace` 252 253* Default: 254* Type: String (can be set multiple times) 255 256Enable running a command in the context of the configured workspaces of the 257current project while filtering by running only the workspaces defined by 258this configuration option. 259 260Valid values for the `workspace` config are either: 261 262* Workspace names 263* Path to a workspace directory 264* Path to a parent workspace directory (will result in selecting all 265 workspaces within that folder) 266 267When set for the `npm init` command, this may be set to the folder of a 268workspace which does not yet exist, to create the folder and set it up as a 269brand new workspace within the project. 270 271This value is not exported to the environment for child processes. 272 273#### `workspaces` 274 275* Default: null 276* Type: null or Boolean 277 278Set to true to run the command in the context of **all** configured 279workspaces. 280 281Explicitly setting this to false will cause commands like `install` to 282ignore workspaces altogether. When not set explicitly: 283 284- Commands that operate on the `node_modules` tree (install, update, etc.) 285will link workspaces into the `node_modules` folder. - Commands that do 286other things (test, exec, publish, etc.) will operate on the root project, 287_unless_ one or more workspaces are specified in the `workspace` config. 288 289This value is not exported to the environment for child processes. 290 291#### `include-workspace-root` 292 293* Default: false 294* Type: Boolean 295 296Include the workspace root when workspaces are enabled for a command. 297 298When false, specifying individual workspaces via the `workspace` config, or 299all workspaces via the `workspaces` flag, will cause npm to operate only on 300the specified workspaces, and not on the root project. 301 302This value is not exported to the environment for child processes. 303 304#### `install-links` 305 306* Default: false 307* Type: Boolean 308 309When set file: protocol dependencies will be packed and installed as regular 310dependencies instead of creating a symlink. This option has no effect on 311workspaces. 312 313 314 315### See Also 316 317* [npm find-dupes](/commands/npm-find-dupes) 318* [npm ls](/commands/npm-ls) 319* [npm update](/commands/npm-update) 320* [npm install](/commands/npm-install) 321