npm-link.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <html><head>
  2. <title>npm-link</title>
  3. <style>
  4. body {
  5. background-color: #ffffff;
  6. color: #24292e;
  7. margin: 0;
  8. line-height: 1.5;
  9. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  10. }
  11. #rainbar {
  12. height: 10px;
  13. background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
  14. }
  15. a {
  16. text-decoration: none;
  17. color: #0366d6;
  18. }
  19. a:hover {
  20. text-decoration: underline;
  21. }
  22. pre {
  23. margin: 1em 0px;
  24. padding: 1em;
  25. border: solid 1px #e1e4e8;
  26. border-radius: 6px;
  27. display: block;
  28. overflow: auto;
  29. white-space: pre;
  30. background-color: #f6f8fa;
  31. color: #393a34;
  32. }
  33. code {
  34. font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
  35. font-size: 85%;
  36. padding: 0.2em 0.4em;
  37. background-color: #f6f8fa;
  38. color: #393a34;
  39. }
  40. pre > code {
  41. padding: 0;
  42. background-color: inherit;
  43. color: inherit;
  44. }
  45. h1, h2, h3 {
  46. font-weight: 600;
  47. }
  48. #logobar {
  49. background-color: #333333;
  50. margin: 0 auto;
  51. padding: 1em 4em;
  52. }
  53. #logobar .logo {
  54. float: left;
  55. }
  56. #logobar .title {
  57. font-weight: 600;
  58. color: #dddddd;
  59. float: left;
  60. margin: 5px 0 0 1em;
  61. }
  62. #logobar:after {
  63. content: "";
  64. display: block;
  65. clear: both;
  66. }
  67. #content {
  68. margin: 0 auto;
  69. padding: 0 4em;
  70. }
  71. #table_of_contents > h2 {
  72. font-size: 1.17em;
  73. }
  74. #table_of_contents ul:first-child {
  75. border: solid 1px #e1e4e8;
  76. border-radius: 6px;
  77. padding: 1em;
  78. background-color: #f6f8fa;
  79. color: #393a34;
  80. }
  81. #table_of_contents ul {
  82. list-style-type: none;
  83. padding-left: 1.5em;
  84. }
  85. #table_of_contents li {
  86. font-size: 0.9em;
  87. }
  88. #table_of_contents li a {
  89. color: #000000;
  90. }
  91. header.title {
  92. border-bottom: solid 1px #e1e4e8;
  93. }
  94. header.title > h1 {
  95. margin-bottom: 0.25em;
  96. }
  97. header.title > .description {
  98. display: block;
  99. margin-bottom: 0.5em;
  100. line-height: 1;
  101. }
  102. footer#edit {
  103. border-top: solid 1px #e1e4e8;
  104. margin: 3em 0 4em 0;
  105. padding-top: 2em;
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <div id="banner">
  111. <div id="rainbar"></div>
  112. <div id="logobar">
  113. <svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
  114. <polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
  115. <polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
  116. </svg>
  117. <div class="title">
  118. npm command-line interface
  119. </div>
  120. </div>
  121. </div>
  122. <section id="content">
  123. <header class="title">
  124. <h1 id="npm-link">npm-link</h1>
  125. <span class="description">Symlink a package folder</span>
  126. </header>
  127. <section id="table_of_contents">
  128. <h2 id="table-of-contents">Table of contents</h2>
  129. <div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><li><a href="#caveat">Caveat</a></li><li><a href="#workspace-usage">Workspace Usage</a></li><li><a href="#configuration">Configuration</a></li><ul><li><a href="#save"><code>save</code></a></li><li><a href="#save-exact"><code>save-exact</code></a></li><li><a href="#global"><code>global</code></a></li><li><a href="#global-style"><code>global-style</code></a></li><li><a href="#legacy-bundling"><code>legacy-bundling</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="#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></ul><li><a href="#see-also">See Also</a></li></ul></div>
  130. </section>
  131. <div id="_content"><h3 id="synopsis">Synopsis</h3>
  132. <pre lang="bash"><code>npm link (in package dir)
  133. npm link [&lt;@scope&gt;/]&lt;pkg&gt;[@&lt;version&gt;]
  134. alias: npm ln
  135. </code></pre>
  136. <h3 id="description">Description</h3>
  137. <p>This is handy for installing your own stuff, so that you can work on it and
  138. test iteratively without having to continually rebuild.</p>
  139. <p>Package linking is a two-step process.</p>
  140. <p>First, <code>npm link</code> in a package folder will create a symlink in the global
  141. folder <code>{prefix}/lib/node_modules/&lt;package&gt;</code> that links to the package
  142. where the <code>npm link</code> command was executed. It will also link any bins in
  143. the package to <code>{prefix}/bin/{name}</code>. Note that <code>npm link</code> uses the global
  144. prefix (see <code>npm prefix -g</code> for its value).</p>
  145. <p>Next, in some other location, <code>npm link package-name</code> will create a
  146. symbolic link from globally-installed <code>package-name</code> to <code>node_modules/</code> of
  147. the current folder.</p>
  148. <p>Note that <code>package-name</code> is taken from <code>package.json</code>, <em>not</em> from the
  149. directory name.</p>
  150. <p>The package name can be optionally prefixed with a scope. See
  151. <a href="../using-npm/scope.html"><code>scope</code></a>. The scope must be preceded by an @-symbol and
  152. followed by a slash.</p>
  153. <p>When creating tarballs for <code>npm publish</code>, the linked packages are
  154. “snapshotted” to their current state by resolving the symbolic links, if
  155. they are included in <code>bundleDependencies</code>.</p>
  156. <p>For example:</p>
  157. <pre lang="bash"><code>cd ~/projects/node-redis # go into the package directory
  158. npm link # creates global link
  159. cd ~/projects/node-bloggy # go into some other package directory.
  160. npm link redis # link-install the package
  161. </code></pre>
  162. <p>Now, any changes to <code>~/projects/node-redis</code> will be reflected in
  163. <code>~/projects/node-bloggy/node_modules/node-redis/</code>. Note that the link
  164. should be to the package name, not the directory name for that package.</p>
  165. <p>You may also shortcut the two steps in one. For example, to do the
  166. above use-case in a shorter way:</p>
  167. <pre lang="bash"><code>cd ~/projects/node-bloggy # go into the dir of your main project
  168. npm link ../node-redis # link the dir of your dependency
  169. </code></pre>
  170. <p>The second line is the equivalent of doing:</p>
  171. <pre lang="bash"><code>(cd ../node-redis; npm link)
  172. npm link redis
  173. </code></pre>
  174. <p>That is, it first creates a global link, and then links the global
  175. installation target into your project’s <code>node_modules</code> folder.</p>
  176. <p>Note that in this case, you are referring to the directory name,
  177. <code>node-redis</code>, rather than the package name <code>redis</code>.</p>
  178. <p>If your linked package is scoped (see <a href="../using-npm/scope.html"><code>scope</code></a>) your
  179. link command must include that scope, e.g.</p>
  180. <pre lang="bash"><code>npm link @myorg/privatepackage
  181. </code></pre>
  182. <h3 id="caveat">Caveat</h3>
  183. <p>Note that package dependencies linked in this way are <em>not</em> saved to
  184. <code>package.json</code> by default, on the assumption that the intention is to have
  185. a link stand in for a regular non-link dependency. Otherwise, for example,
  186. if you depend on <code>redis@^3.0.1</code>, and ran <code>npm link redis</code>, it would replace
  187. the <code>^3.0.1</code> dependency with <code>file:../path/to/node-redis</code>, which you
  188. probably don’t want! Additionally, other users or developers on your
  189. project would run into issues if they do not have their folders set up
  190. exactly the same as yours.</p>
  191. <p>If you are adding a <em>new</em> dependency as a link, you should add it to the
  192. relevant metadata by running <code>npm install &lt;dep&gt; --package-lock-only</code>.</p>
  193. <p>If you <em>want</em> to save the <code>file:</code> reference in your <code>package.json</code> and
  194. <code>package-lock.json</code> files, you can use <code>npm link &lt;dep&gt; --save</code> to do so.</p>
  195. <h3 id="workspace-usage">Workspace Usage</h3>
  196. <p><code>npm link &lt;pkg&gt; --workspace &lt;name&gt;</code> will link the relevant package as a
  197. dependency of the specified workspace(s). Note that It may actually be
  198. linked into the parent project’s <code>node_modules</code> folder, if there are no
  199. conflicting dependencies.</p>
  200. <p><code>npm link --workspace &lt;name&gt;</code> will create a global link to the specified
  201. workspace(s).</p>
  202. <h3 id="configuration">Configuration</h3>
  203. <!-- raw HTML omitted -->
  204. <!-- raw HTML omitted -->
  205. <!-- raw HTML omitted -->
  206. <h4 id="save"><code>save</code></h4>
  207. <ul>
  208. <li>Default: true</li>
  209. <li>Type: Boolean</li>
  210. </ul>
  211. <p>Save installed packages to a package.json file as dependencies.</p>
  212. <p>When used with the <code>npm rm</code> command, removes the dependency from
  213. package.json.</p>
  214. <!-- raw HTML omitted -->
  215. <!-- raw HTML omitted -->
  216. <h4 id="save-exact"><code>save-exact</code></h4>
  217. <ul>
  218. <li>Default: false</li>
  219. <li>Type: Boolean</li>
  220. </ul>
  221. <p>Dependencies saved to package.json will be configured with an exact version
  222. rather than using npm’s default semver range operator.</p>
  223. <!-- raw HTML omitted -->
  224. <!-- raw HTML omitted -->
  225. <h4 id="global"><code>global</code></h4>
  226. <ul>
  227. <li>Default: false</li>
  228. <li>Type: Boolean</li>
  229. </ul>
  230. <p>Operates in “global” mode, so that packages are installed into the <code>prefix</code>
  231. folder instead of the current working directory. See
  232. <a href="../configuring-npm/folders.html">folders</a> for more on the differences in behavior.</p>
  233. <ul>
  234. <li>packages are installed into the <code>{prefix}/lib/node_modules</code> folder, instead
  235. of the current working directory.</li>
  236. <li>bin files are linked to <code>{prefix}/bin</code></li>
  237. <li>man pages are linked to <code>{prefix}/share/man</code></li>
  238. </ul>
  239. <!-- raw HTML omitted -->
  240. <!-- raw HTML omitted -->
  241. <h4 id="global-style"><code>global-style</code></h4>
  242. <ul>
  243. <li>Default: false</li>
  244. <li>Type: Boolean</li>
  245. </ul>
  246. <p>Causes npm to install the package into your local <code>node_modules</code> folder with
  247. the same layout it uses with the global <code>node_modules</code> folder. Only your
  248. direct dependencies will show in <code>node_modules</code> and everything they depend
  249. on will be flattened in their <code>node_modules</code> folders. This obviously will
  250. eliminate some deduping. If used with <code>legacy-bundling</code>, <code>legacy-bundling</code>
  251. will be preferred.</p>
  252. <!-- raw HTML omitted -->
  253. <!-- raw HTML omitted -->
  254. <h4 id="legacy-bundling"><code>legacy-bundling</code></h4>
  255. <ul>
  256. <li>Default: false</li>
  257. <li>Type: Boolean</li>
  258. </ul>
  259. <p>Causes npm to install the package such that versions of npm prior to 1.4,
  260. such as the one included with node 0.8, can install the package. This
  261. eliminates all automatic deduping. If used with <code>global-style</code> this option
  262. will be preferred.</p>
  263. <!-- raw HTML omitted -->
  264. <!-- raw HTML omitted -->
  265. <h4 id="strict-peer-deps"><code>strict-peer-deps</code></h4>
  266. <ul>
  267. <li>Default: false</li>
  268. <li>Type: Boolean</li>
  269. </ul>
  270. <p>If set to <code>true</code>, and <code>--legacy-peer-deps</code> is not set, then <em>any</em>
  271. conflicting <code>peerDependencies</code> will be treated as an install failure, even
  272. if npm could reasonably guess the appropriate resolution based on non-peer
  273. dependency relationships.</p>
  274. <p>By default, conflicting <code>peerDependencies</code> deep in the dependency graph will
  275. be resolved using the nearest non-peer dependency specification, even if
  276. doing so will result in some packages receiving a peer dependency outside
  277. the range set in their package’s <code>peerDependencies</code> object.</p>
  278. <p>When such and override is performed, a warning is printed, explaining the
  279. conflict and the packages involved. If <code>--strict-peer-deps</code> is set, then
  280. this warning is treated as a failure.</p>
  281. <!-- raw HTML omitted -->
  282. <!-- raw HTML omitted -->
  283. <h4 id="package-lock"><code>package-lock</code></h4>
  284. <ul>
  285. <li>Default: true</li>
  286. <li>Type: Boolean</li>
  287. </ul>
  288. <p>If set to false, then ignore <code>package-lock.json</code> files when installing. This
  289. will also prevent <em>writing</em> <code>package-lock.json</code> if <code>save</code> is true.</p>
  290. <p>When package package-locks are disabled, automatic pruning of extraneous
  291. modules will also be disabled. To remove extraneous modules with
  292. package-locks disabled use <code>npm prune</code>.</p>
  293. <!-- raw HTML omitted -->
  294. <!-- raw HTML omitted -->
  295. <h4 id="omit"><code>omit</code></h4>
  296. <ul>
  297. <li>Default: ‘dev’ if the <code>NODE_ENV</code> environment variable is set to
  298. ‘production’, otherwise empty.</li>
  299. <li>Type: “dev”, “optional”, or “peer” (can be set multiple times)</li>
  300. </ul>
  301. <p>Dependency types to omit from the installation tree on disk.</p>
  302. <p>Note that these dependencies <em>are</em> still resolved and added to the
  303. <code>package-lock.json</code> or <code>npm-shrinkwrap.json</code> file. They are just not
  304. physically installed on disk.</p>
  305. <p>If a package type appears in both the <code>--include</code> and <code>--omit</code> lists, then
  306. it will be included.</p>
  307. <p>If the resulting omit list includes <code>'dev'</code>, then the <code>NODE_ENV</code> environment
  308. variable will be set to <code>'production'</code> for all lifecycle scripts.</p>
  309. <!-- raw HTML omitted -->
  310. <!-- raw HTML omitted -->
  311. <h4 id="ignore-scripts"><code>ignore-scripts</code></h4>
  312. <ul>
  313. <li>Default: false</li>
  314. <li>Type: Boolean</li>
  315. </ul>
  316. <p>If true, npm does not run scripts specified in package.json files.</p>
  317. <p>Note that commands explicitly intended to run a particular script, such as
  318. <code>npm start</code>, <code>npm stop</code>, <code>npm restart</code>, <code>npm test</code>, and <code>npm run-script</code>
  319. will still run their intended script if <code>ignore-scripts</code> is set, but they
  320. will <em>not</em> run any pre- or post-scripts.</p>
  321. <!-- raw HTML omitted -->
  322. <!-- raw HTML omitted -->
  323. <h4 id="audit"><code>audit</code></h4>
  324. <ul>
  325. <li>Default: true</li>
  326. <li>Type: Boolean</li>
  327. </ul>
  328. <p>When “true” submit audit reports alongside the current npm command to the
  329. default registry and all registries configured for scopes. See the
  330. documentation for <a href="../commands/npm-audit.html"><code>npm audit</code></a> for details on what is
  331. submitted.</p>
  332. <!-- raw HTML omitted -->
  333. <!-- raw HTML omitted -->
  334. <h4 id="bin-links"><code>bin-links</code></h4>
  335. <ul>
  336. <li>Default: true</li>
  337. <li>Type: Boolean</li>
  338. </ul>
  339. <p>Tells npm to create symlinks (or <code>.cmd</code> shims on Windows) for package
  340. executables.</p>
  341. <p>Set to false to have it not do this. This can be used to work around the
  342. fact that some file systems don’t support symlinks, even on ostensibly Unix
  343. systems.</p>
  344. <!-- raw HTML omitted -->
  345. <!-- raw HTML omitted -->
  346. <h4 id="fund"><code>fund</code></h4>
  347. <ul>
  348. <li>Default: true</li>
  349. <li>Type: Boolean</li>
  350. </ul>
  351. <p>When “true” displays the message at the end of each <code>npm install</code>
  352. acknowledging the number of dependencies looking for funding. See <a href="../commands/npm-fund.html"><code>npm fund</code></a> for details.</p>
  353. <!-- raw HTML omitted -->
  354. <!-- raw HTML omitted -->
  355. <h4 id="dry-run"><code>dry-run</code></h4>
  356. <ul>
  357. <li>Default: false</li>
  358. <li>Type: Boolean</li>
  359. </ul>
  360. <p>Indicates that you don’t want npm to make any changes and that it should
  361. only report what it would have done. This can be passed into any of the
  362. commands that modify your local installation, eg, <code>install</code>, <code>update</code>,
  363. <code>dedupe</code>, <code>uninstall</code>, as well as <code>pack</code> and <code>publish</code>.</p>
  364. <p>Note: This is NOT honored by other network related commands, eg <code>dist-tags</code>,
  365. <code>owner</code>, etc.</p>
  366. <!-- raw HTML omitted -->
  367. <!-- raw HTML omitted -->
  368. <h4 id="workspace"><code>workspace</code></h4>
  369. <ul>
  370. <li>Default:</li>
  371. <li>Type: String (can be set multiple times)</li>
  372. </ul>
  373. <p>Enable running a command in the context of the configured workspaces of the
  374. current project while filtering by running only the workspaces defined by
  375. this configuration option.</p>
  376. <p>Valid values for the <code>workspace</code> config are either:</p>
  377. <ul>
  378. <li>Workspace names</li>
  379. <li>Path to a workspace directory</li>
  380. <li>Path to a parent workspace directory (will result in selecting all
  381. workspaces within that folder)</li>
  382. </ul>
  383. <p>When set for the <code>npm init</code> command, this may be set to the folder of a
  384. workspace which does not yet exist, to create the folder and set it up as a
  385. brand new workspace within the project.</p>
  386. <p>This value is not exported to the environment for child processes.</p>
  387. <!-- raw HTML omitted -->
  388. <!-- raw HTML omitted -->
  389. <h4 id="workspaces"><code>workspaces</code></h4>
  390. <ul>
  391. <li>Default: null</li>
  392. <li>Type: null or Boolean</li>
  393. </ul>
  394. <p>Set to true to run the command in the context of <strong>all</strong> configured
  395. workspaces.</p>
  396. <p>Explicitly setting this to false will cause commands like <code>install</code> to
  397. ignore workspaces altogether. When not set explicitly:</p>
  398. <ul>
  399. <li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
  400. will link workspaces into the <code>node_modules</code> folder. - Commands that do
  401. other things (test, exec, publish, etc.) will operate on the root project,
  402. <em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
  403. </ul>
  404. <p>This value is not exported to the environment for child processes.</p>
  405. <!-- raw HTML omitted -->
  406. <!-- raw HTML omitted -->
  407. <h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
  408. <ul>
  409. <li>Default: false</li>
  410. <li>Type: Boolean</li>
  411. </ul>
  412. <p>Include the workspace root when workspaces are enabled for a command.</p>
  413. <p>When false, specifying individual workspaces via the <code>workspace</code> config, or
  414. all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
  415. the specified workspaces, and not on the root project.</p>
  416. <!-- raw HTML omitted -->
  417. <!-- raw HTML omitted -->
  418. <!-- raw HTML omitted -->
  419. <h3 id="see-also">See Also</h3>
  420. <ul>
  421. <li><a href="../using-npm/developers.html">npm developers</a></li>
  422. <li><a href="../configuring-npm/package-json.html">package.json</a></li>
  423. <li><a href="../commands/npm-install.html">npm install</a></li>
  424. <li><a href="../configuring-npm/folders.html">npm folders</a></li>
  425. <li><a href="../commands/npm-config.html">npm config</a></li>
  426. <li><a href="../configuring-npm/npmrc.html">npmrc</a></li>
  427. </ul>
  428. </div>
  429. <footer id="edit">
  430. <a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-link.md">
  431. <svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
  432. <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>
  433. </svg>
  434. Edit this page on GitHub
  435. </a>
  436. </footer>
  437. </section>
  438. </body></html>