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