• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html><html><head>
2<meta charset="utf-8">
3<title>npm-dedupe</title>
4<style>
5body {
6    background-color: #ffffff;
7    color: #24292e;
8
9    margin: 0;
10
11    line-height: 1.5;
12
13    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
14}
15#rainbar {
16    height: 10px;
17    background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
18}
19
20a {
21    text-decoration: none;
22    color: #0366d6;
23}
24a:hover {
25    text-decoration: underline;
26}
27
28pre {
29    margin: 1em 0px;
30    padding: 1em;
31    border: solid 1px #e1e4e8;
32    border-radius: 6px;
33
34    display: block;
35    overflow: auto;
36
37    white-space: pre;
38
39    background-color: #f6f8fa;
40    color: #393a34;
41}
42code {
43    font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
44    font-size: 85%;
45    padding: 0.2em 0.4em;
46    background-color: #f6f8fa;
47    color: #393a34;
48}
49pre > code {
50    padding: 0;
51    background-color: inherit;
52    color: inherit;
53}
54h1, h2, h3 {
55    font-weight: 600;
56}
57
58#logobar {
59    background-color: #333333;
60    margin: 0 auto;
61    padding: 1em 4em;
62}
63#logobar .logo {
64    float: left;
65}
66#logobar .title {
67    font-weight: 600;
68    color: #dddddd;
69    float: left;
70    margin: 5px 0 0 1em;
71}
72#logobar:after {
73    content: "";
74    display: block;
75    clear: both;
76}
77
78#content {
79    margin: 0 auto;
80    padding: 0 4em;
81}
82
83#table_of_contents > h2 {
84    font-size: 1.17em;
85}
86#table_of_contents ul:first-child {
87    border: solid 1px #e1e4e8;
88    border-radius: 6px;
89    padding: 1em;
90    background-color: #f6f8fa;
91    color: #393a34;
92}
93#table_of_contents ul {
94    list-style-type: none;
95    padding-left: 1.5em;
96}
97#table_of_contents li {
98    font-size: 0.9em;
99}
100#table_of_contents li a {
101    color: #000000;
102}
103
104header.title {
105    border-bottom: solid 1px #e1e4e8;
106}
107header.title > h1 {
108    margin-bottom: 0.25em;
109}
110header.title > .description {
111    display: block;
112    margin-bottom: 0.5em;
113    line-height: 1;
114}
115
116footer#edit {
117    border-top: solid 1px #e1e4e8;
118    margin: 3em 0 4em 0;
119    padding-top: 2em;
120}
121</style>
122</head>
123<body>
124<div id="banner">
125<div id="rainbar"></div>
126<div id="logobar">
127<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
128<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
129<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
130</svg>
131<div class="title">
132npm command-line interface
133</div>
134</div>
135</div>
136
137<section id="content">
138<header class="title">
139<h1 id="npm-dedupe">npm-dedupe</h1>
140<span class="description">Reduce duplication in the package tree</span>
141</header>
142
143<section id="table_of_contents">
144<h2 id="table-of-contents">Table of contents</h2>
145<div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><li><a href="#configuration">Configuration</a></li><ul><li><a href="#install-strategy"><code>install-strategy</code></a></li><li><a href="#legacy-bundling"><code>legacy-bundling</code></a></li><li><a href="#global-style"><code>global-style</code></a></li><li><a href="#strict-peer-deps"><code>strict-peer-deps</code></a></li><li><a href="#package-lock"><code>package-lock</code></a></li><li><a href="#omit"><code>omit</code></a></li><li><a href="#include"><code>include</code></a></li><li><a href="#ignore-scripts"><code>ignore-scripts</code></a></li><li><a href="#audit"><code>audit</code></a></li><li><a href="#bin-links"><code>bin-links</code></a></li><li><a href="#fund"><code>fund</code></a></li><li><a href="#dry-run"><code>dry-run</code></a></li><li><a href="#workspace"><code>workspace</code></a></li><li><a href="#workspaces"><code>workspaces</code></a></li><li><a href="#include-workspace-root"><code>include-workspace-root</code></a></li><li><a href="#install-links"><code>install-links</code></a></li></ul><li><a href="#see-also">See Also</a></li></ul></div>
146</section>
147
148<div id="_content"><h3 id="synopsis">Synopsis</h3>
149<pre><code class="language-bash">npm dedupe
150
151alias: ddp
152</code></pre>
153<h3 id="description">Description</h3>
154<p>Searches the local package tree and attempts to simplify the overall
155structure by moving dependencies further up the tree, where they can
156be more effectively shared by multiple dependent packages.</p>
157<p>For example, consider this dependency graph:</p>
158<pre><code>a
159+-- b &lt;-- depends on c@1.0.x
160|   `-- c@1.0.3
161`-- d &lt;-- depends on c@~1.0.9
162    `-- c@1.0.10
163</code></pre>
164<p>In this case, <code>npm dedupe</code> will transform the tree to:</p>
165<pre><code class="language-bash">a
166+-- b
167+-- d
168`-- c@1.0.10
169</code></pre>
170<p>Because of the hierarchical nature of node's module lookup, b and d
171will both get their dependency met by the single c package at the root
172level of the tree.</p>
173<p>In some cases, you may have a dependency graph like this:</p>
174<pre><code>a
175+-- b &lt;-- depends on c@1.0.x
176+-- c@1.0.3
177`-- d &lt;-- depends on c@1.x
178    `-- c@1.9.9
179</code></pre>
180<p>During the installation process, the <code>c@1.0.3</code> dependency for <code>b</code> was
181placed in the root of the tree.  Though <code>d</code>'s dependency on <code>c@1.x</code> could
182have been satisfied by <code>c@1.0.3</code>, the newer <code>c@1.9.0</code> dependency was used,
183because npm favors updates by default, even when doing so causes
184duplication.</p>
185<p>Running <code>npm dedupe</code> will cause npm to note the duplication and
186re-evaluate, deleting the nested <code>c</code> module, because the one in the root is
187sufficient.</p>
188<p>To prefer deduplication over novelty during the installation process, run
189<code>npm install --prefer-dedupe</code> or <code>npm config set prefer-dedupe true</code>.</p>
190<p>Arguments are ignored. Dedupe always acts on the entire tree.</p>
191<p>Note that this operation transforms the dependency tree, but will never
192result in new modules being installed.</p>
193<p>Using <code>npm find-dupes</code> will run the command in <code>--dry-run</code> mode.</p>
194<p>Note: <code>npm dedupe</code> will never update the semver values of direct
195dependencies in your project <code>package.json</code>, if you want to update
196values in <code>package.json</code> you can run: <code>npm update --save</code> instead.</p>
197<h3 id="configuration">Configuration</h3>
198<h4 id="install-strategy"><code>install-strategy</code></h4>
199<ul>
200<li>Default: "hoisted"</li>
201<li>Type: "hoisted", "nested", "shallow", or "linked"</li>
202</ul>
203<p>Sets the strategy for installing packages in node_modules. hoisted
204(default): Install non-duplicated in top-level, and duplicated as necessary
205within directory structure. nested: (formerly --legacy-bundling) install in
206place, no hoisting. shallow (formerly --global-style) only install direct
207deps at top-level. linked: (experimental) install in node_modules/.store,
208link in place, unhoisted.</p>
209<h4 id="legacy-bundling"><code>legacy-bundling</code></h4>
210<ul>
211<li>Default: false</li>
212<li>Type: Boolean</li>
213<li>DEPRECATED: This option has been deprecated in favor of
214<code>--install-strategy=nested</code></li>
215</ul>
216<p>Instead of hoisting package installs in <code>node_modules</code>, install packages in
217the same manner that they are depended on. This may cause very deep
218directory structures and duplicate package installs as there is no
219de-duplicating. Sets <code>--install-strategy=nested</code>.</p>
220<h4 id="global-style"><code>global-style</code></h4>
221<ul>
222<li>Default: false</li>
223<li>Type: Boolean</li>
224<li>DEPRECATED: This option has been deprecated in favor of
225<code>--install-strategy=shallow</code></li>
226</ul>
227<p>Only install direct dependencies in the top level <code>node_modules</code>, but hoist
228on deeper dependencies. Sets <code>--install-strategy=shallow</code>.</p>
229<h4 id="strict-peer-deps"><code>strict-peer-deps</code></h4>
230<ul>
231<li>Default: false</li>
232<li>Type: Boolean</li>
233</ul>
234<p>If set to <code>true</code>, and <code>--legacy-peer-deps</code> is not set, then <em>any</em>
235conflicting <code>peerDependencies</code> will be treated as an install failure, even
236if npm could reasonably guess the appropriate resolution based on non-peer
237dependency relationships.</p>
238<p>By default, conflicting <code>peerDependencies</code> deep in the dependency graph will
239be resolved using the nearest non-peer dependency specification, even if
240doing so will result in some packages receiving a peer dependency outside
241the range set in their package's <code>peerDependencies</code> object.</p>
242<p>When such an override is performed, a warning is printed, explaining the
243conflict and the packages involved. If <code>--strict-peer-deps</code> is set, then
244this warning is treated as a failure.</p>
245<h4 id="package-lock"><code>package-lock</code></h4>
246<ul>
247<li>Default: true</li>
248<li>Type: Boolean</li>
249</ul>
250<p>If set to false, then ignore <code>package-lock.json</code> files when installing. This
251will also prevent <em>writing</em> <code>package-lock.json</code> if <code>save</code> is true.</p>
252<h4 id="omit"><code>omit</code></h4>
253<ul>
254<li>Default: 'dev' if the <code>NODE_ENV</code> environment variable is set to
255'production', otherwise empty.</li>
256<li>Type: "dev", "optional", or "peer" (can be set multiple times)</li>
257</ul>
258<p>Dependency types to omit from the installation tree on disk.</p>
259<p>Note that these dependencies <em>are</em> still resolved and added to the
260<code>package-lock.json</code> or <code>npm-shrinkwrap.json</code> file. They are just not
261physically installed on disk.</p>
262<p>If a package type appears in both the <code>--include</code> and <code>--omit</code> lists, then
263it will be included.</p>
264<p>If the resulting omit list includes <code>'dev'</code>, then the <code>NODE_ENV</code> environment
265variable will be set to <code>'production'</code> for all lifecycle scripts.</p>
266<h4 id="include"><code>include</code></h4>
267<ul>
268<li>Default:</li>
269<li>Type: "prod", "dev", "optional", or "peer" (can be set multiple times)</li>
270</ul>
271<p>Option that allows for defining which types of dependencies to install.</p>
272<p>This is the inverse of <code>--omit=&lt;type&gt;</code>.</p>
273<p>Dependency types specified in <code>--include</code> will not be omitted, regardless of
274the order in which omit/include are specified on the command-line.</p>
275<h4 id="ignore-scripts"><code>ignore-scripts</code></h4>
276<ul>
277<li>Default: false</li>
278<li>Type: Boolean</li>
279</ul>
280<p>If true, npm does not run scripts specified in package.json files.</p>
281<p>Note that commands explicitly intended to run a particular script, such as
282<code>npm start</code>, <code>npm stop</code>, <code>npm restart</code>, <code>npm test</code>, and <code>npm run-script</code>
283will still run their intended script if <code>ignore-scripts</code> is set, but they
284will <em>not</em> run any pre- or post-scripts.</p>
285<h4 id="audit"><code>audit</code></h4>
286<ul>
287<li>Default: true</li>
288<li>Type: Boolean</li>
289</ul>
290<p>When "true" submit audit reports alongside the current npm command to the
291default registry and all registries configured for scopes. See the
292documentation for <a href="../commands/npm-audit.html"><code>npm audit</code></a> for details on what is
293submitted.</p>
294<h4 id="bin-links"><code>bin-links</code></h4>
295<ul>
296<li>Default: true</li>
297<li>Type: Boolean</li>
298</ul>
299<p>Tells npm to create symlinks (or <code>.cmd</code> shims on Windows) for package
300executables.</p>
301<p>Set to false to have it not do this. This can be used to work around the
302fact that some file systems don't support symlinks, even on ostensibly Unix
303systems.</p>
304<h4 id="fund"><code>fund</code></h4>
305<ul>
306<li>Default: true</li>
307<li>Type: Boolean</li>
308</ul>
309<p>When "true" displays the message at the end of each <code>npm install</code>
310acknowledging the number of dependencies looking for funding. See <a href="../commands/npm-fund.html"><code>npm fund</code></a> for details.</p>
311<h4 id="dry-run"><code>dry-run</code></h4>
312<ul>
313<li>Default: false</li>
314<li>Type: Boolean</li>
315</ul>
316<p>Indicates that you don't want npm to make any changes and that it should
317only report what it would have done. This can be passed into any of the
318commands that modify your local installation, eg, <code>install</code>, <code>update</code>,
319<code>dedupe</code>, <code>uninstall</code>, as well as <code>pack</code> and <code>publish</code>.</p>
320<p>Note: This is NOT honored by other network related commands, eg <code>dist-tags</code>,
321<code>owner</code>, etc.</p>
322<h4 id="workspace"><code>workspace</code></h4>
323<ul>
324<li>Default:</li>
325<li>Type: String (can be set multiple times)</li>
326</ul>
327<p>Enable running a command in the context of the configured workspaces of the
328current project while filtering by running only the workspaces defined by
329this configuration option.</p>
330<p>Valid values for the <code>workspace</code> config are either:</p>
331<ul>
332<li>Workspace names</li>
333<li>Path to a workspace directory</li>
334<li>Path to a parent workspace directory (will result in selecting all
335workspaces within that folder)</li>
336</ul>
337<p>When set for the <code>npm init</code> command, this may be set to the folder of a
338workspace which does not yet exist, to create the folder and set it up as a
339brand new workspace within the project.</p>
340<p>This value is not exported to the environment for child processes.</p>
341<h4 id="workspaces"><code>workspaces</code></h4>
342<ul>
343<li>Default: null</li>
344<li>Type: null or Boolean</li>
345</ul>
346<p>Set to true to run the command in the context of <strong>all</strong> configured
347workspaces.</p>
348<p>Explicitly setting this to false will cause commands like <code>install</code> to
349ignore workspaces altogether. When not set explicitly:</p>
350<ul>
351<li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
352will link workspaces into the <code>node_modules</code> folder. - Commands that do
353other things (test, exec, publish, etc.) will operate on the root project,
354<em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
355</ul>
356<p>This value is not exported to the environment for child processes.</p>
357<h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
358<ul>
359<li>Default: false</li>
360<li>Type: Boolean</li>
361</ul>
362<p>Include the workspace root when workspaces are enabled for a command.</p>
363<p>When false, specifying individual workspaces via the <code>workspace</code> config, or
364all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
365the specified workspaces, and not on the root project.</p>
366<p>This value is not exported to the environment for child processes.</p>
367<h4 id="install-links"><code>install-links</code></h4>
368<ul>
369<li>Default: false</li>
370<li>Type: Boolean</li>
371</ul>
372<p>When set file: protocol dependencies will be packed and installed as regular
373dependencies instead of creating a symlink. This option has no effect on
374workspaces.</p>
375<h3 id="see-also">See Also</h3>
376<ul>
377<li><a href="../commands/npm-find-dupes.html">npm find-dupes</a></li>
378<li><a href="../commands/npm-ls.html">npm ls</a></li>
379<li><a href="../commands/npm-update.html">npm update</a></li>
380<li><a href="../commands/npm-install.html">npm install</a></li>
381</ul></div>
382
383<footer id="edit">
384<a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-dedupe.md">
385<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
386<path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path>
387</svg>
388Edit this page on GitHub
389</a>
390</footer>
391</section>
392
393
394
395</body></html>