npm-dedupe.html 17 KB

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