Team Ai
Datasetpublic

codekingpro/portable-devtools

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