npm-publish.1 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. .TH "NPM-PUBLISH" "1" "March 2026" "NPM@11.12.0" ""
  2. .SH "NAME"
  3. \fBnpm-publish\fR - Publish a package
  4. .SS "Synopsis"
  5. .P
  6. .RS 2
  7. .nf
  8. npm publish <package-spec>
  9. .fi
  10. .RE
  11. .SS "Description"
  12. .P
  13. Publishes a package to the registry so that it can be installed by name.
  14. .SS "Examples"
  15. .P
  16. Publish the package in the current directory:
  17. .P
  18. .RS 2
  19. .nf
  20. npm publish
  21. .fi
  22. .RE
  23. .P
  24. Publish a specific workspace:
  25. .P
  26. .RS 2
  27. .nf
  28. npm publish --workspace=<workspace-name>
  29. .fi
  30. .RE
  31. .P
  32. Publish multiple workspaces:
  33. .P
  34. .RS 2
  35. .nf
  36. npm publish --workspace=workspace-a --workspace=workspace-b
  37. .fi
  38. .RE
  39. .P
  40. Publish all workspaces:
  41. .P
  42. .RS 2
  43. .nf
  44. npm publish --workspaces
  45. .fi
  46. .RE
  47. .P
  48. By default npm will publish to the public registry. This can be overridden by specifying a different default registry or using a npm help scope in the name, combined with a scope-configured registry (see \fB\[rs]fBpackage.json\[rs]fR\fR \fI\(la/configuring-npm/package-json\(ra\fR).
  49. .P
  50. A \fBpackage\fR is interpreted the same way as other commands (like \fBnpm install\fR) and can be:
  51. .RS 0
  52. .IP \(bu 4
  53. a) a folder containing a program described by a \fB\[rs]fBpackage.json\[rs]fR\fR \fI\(la/configuring-npm/package-json\(ra\fR file
  54. .IP \(bu 4
  55. b) a gzipped tarball containing (a)
  56. .IP \(bu 4
  57. c) a url that resolves to (b)
  58. .IP \(bu 4
  59. d) a \fB<name>@<version>\fR that is published on the registry (see npm help registry) with (c)
  60. .IP \(bu 4
  61. e) a \fB<name>@<tag>\fR (see npm help dist-tag) that points to (d)
  62. .IP \(bu 4
  63. f) a \fB<name>\fR that has a "latest" tag satisfying (e)
  64. .IP \(bu 4
  65. g) a \fB<git remote url>\fR that resolves to (a)
  66. .RE 0
  67. .P
  68. The publish will fail if the package name and version combination already exists in the specified registry.
  69. .P
  70. Once a package is published with a given name and version, that specific name and version combination can never be used again, even if it is removed with npm help unpublish.
  71. .P
  72. As of \fBnpm@5\fR, both a sha1sum and an integrity field with a sha512sum of the tarball will be submitted to the registry during publication. Subsequent installs will use the strongest supported algorithm to verify downloads.
  73. .P
  74. Similar to \fB--dry-run\fR see npm help pack, which figures out the files to be included and packs them into a tarball to be uploaded to the registry.
  75. .SS "Files included in package"
  76. .P
  77. To see what will be included in your package, run \fBnpm pack --dry-run\fR. All files are included by default, with the following exceptions:
  78. .RS 0
  79. .IP \(bu 4
  80. Certain files that are relevant to package installation and distribution are always included. For example, \fBpackage.json\fR, \fBREADME.md\fR, \fBLICENSE\fR, and so on.
  81. .IP \(bu 4
  82. If there is a "files" list in \fB\[rs]fBpackage.json\[rs]fR\fR \fI\(la/configuring-npm/package-json\(ra\fR, then only the files specified will be included. (If directories are specified, then they will be walked recursively and their contents included, subject to the same ignore rules.)
  83. .IP \(bu 4
  84. If there is a \fB.gitignore\fR or \fB.npmignore\fR file, then ignored files in that and all child directories will be excluded from the package. If \fIboth\fR files exist, then the \fB.gitignore\fR is ignored, and only the \fB.npmignore\fR is used.
  85. .P
  86. \fB.npmignore\fR files follow the \fBsame pattern rules\fR \fI\(lahttps://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#_ignoring\(ra\fR as \fB.gitignore\fR files
  87. .IP \(bu 4
  88. If the file matches certain patterns, then it will \fInever\fR be included, unless explicitly added to the \fB"files"\fR list in \fBpackage.json\fR, or un-ignored with a \fB!\fR rule in a \fB.npmignore\fR or \fB.gitignore\fR file.
  89. .IP \(bu 4
  90. Symbolic links are never included in npm packages.
  91. .RE 0
  92. .P
  93. See npm help developers for full details on what's included in the published package, as well as details on how the package is built.
  94. .P
  95. See \fB\[rs]fBpackage.json\[rs]fR\fR \fI\(la/configuring-npm/package-json\(ra\fR for more info on what can and can't be ignored.
  96. .SS "Configuration"
  97. .SS "\fBtag\fR"
  98. .RS 0
  99. .IP \(bu 4
  100. Default: "latest"
  101. .IP \(bu 4
  102. Type: String
  103. .RE 0
  104. .P
  105. If you ask npm to install a package and don't tell it a specific version, then it will install the specified tag.
  106. .P
  107. It is the tag added to the package@version specified in the \fBnpm dist-tag
  108. add\fR command, if no explicit tag is given.
  109. .P
  110. When used by the \fBnpm diff\fR command, this is the tag used to fetch the tarball that will be compared with the local files by default.
  111. .P
  112. If used in the \fBnpm publish\fR command, this is the tag that will be added to the package submitted to the registry.
  113. .SS "\fBaccess\fR"
  114. .RS 0
  115. .IP \(bu 4
  116. Default: 'public' for new packages, existing packages it will not change the current level
  117. .IP \(bu 4
  118. Type: null, "restricted", or "public"
  119. .RE 0
  120. .P
  121. If you do not want your scoped package to be publicly viewable (and installable) set \fB--access=restricted\fR.
  122. .P
  123. Unscoped packages cannot be set to \fBrestricted\fR.
  124. .P
  125. Note: This defaults to not changing the current access level for existing packages. Specifying a value of \fBrestricted\fR or \fBpublic\fR during publish will change the access for an existing package the same way that \fBnpm access set
  126. status\fR would.
  127. .SS "\fBdry-run\fR"
  128. .RS 0
  129. .IP \(bu 4
  130. Default: false
  131. .IP \(bu 4
  132. Type: Boolean
  133. .RE 0
  134. .P
  135. Indicates that you don't want npm to make any changes and that it should only report what it would have done. This can be passed into any of the commands that modify your local installation, eg, \fBinstall\fR, \fBupdate\fR, \fBdedupe\fR, \fBuninstall\fR, as well as \fBpack\fR and \fBpublish\fR.
  136. .P
  137. Note: This is NOT honored by other network related commands, eg \fBdist-tags\fR, \fBowner\fR, etc.
  138. .SS "\fBotp\fR"
  139. .RS 0
  140. .IP \(bu 4
  141. Default: null
  142. .IP \(bu 4
  143. Type: null or String
  144. .RE 0
  145. .P
  146. This is a one-time password from a two-factor authenticator. It's needed when publishing or changing package permissions with \fBnpm access\fR.
  147. .P
  148. If not set, and a registry response fails with a challenge for a one-time password, npm will prompt on the command line for one.
  149. .SS "\fBworkspace\fR"
  150. .RS 0
  151. .IP \(bu 4
  152. Default:
  153. .IP \(bu 4
  154. Type: String (can be set multiple times)
  155. .RE 0
  156. .P
  157. Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
  158. .P
  159. Valid values for the \fBworkspace\fR config are either:
  160. .RS 0
  161. .IP \(bu 4
  162. Workspace names
  163. .IP \(bu 4
  164. Path to a workspace directory
  165. .IP \(bu 4
  166. Path to a parent workspace directory (will result in selecting all workspaces within that folder)
  167. .RE 0
  168. .P
  169. When set for the \fBnpm init\fR command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
  170. .P
  171. This value is not exported to the environment for child processes.
  172. .SS "\fBworkspaces\fR"
  173. .RS 0
  174. .IP \(bu 4
  175. Default: null
  176. .IP \(bu 4
  177. Type: null or Boolean
  178. .RE 0
  179. .P
  180. Set to true to run the command in the context of \fBall\fR configured workspaces.
  181. .P
  182. Explicitly setting this to false will cause commands like \fBinstall\fR to ignore workspaces altogether. When not set explicitly:
  183. .RS 0
  184. .IP \(bu 4
  185. Commands that operate on the \fBnode_modules\fR tree (install, update, etc.) will link workspaces into the \fBnode_modules\fR folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, \fIunless\fR one or more workspaces are specified in the \fBworkspace\fR config.
  186. .RE 0
  187. .P
  188. This value is not exported to the environment for child processes.
  189. .SS "\fBinclude-workspace-root\fR"
  190. .RS 0
  191. .IP \(bu 4
  192. Default: false
  193. .IP \(bu 4
  194. Type: Boolean
  195. .RE 0
  196. .P
  197. Include the workspace root when workspaces are enabled for a command.
  198. .P
  199. When false, specifying individual workspaces via the \fBworkspace\fR config, or all workspaces via the \fBworkspaces\fR flag, will cause npm to operate only on the specified workspaces, and not on the root project.
  200. .P
  201. This value is not exported to the environment for child processes.
  202. .SS "\fBprovenance\fR"
  203. .RS 0
  204. .IP \(bu 4
  205. Default: false
  206. .IP \(bu 4
  207. Type: Boolean
  208. .RE 0
  209. .P
  210. When publishing from a supported cloud CI/CD system, the package will be publicly linked to where it was built and published from.
  211. .P
  212. This config cannot be used with: \fBprovenance-file\fR
  213. .SS "\fBprovenance-file\fR"
  214. .RS 0
  215. .IP \(bu 4
  216. Default: null
  217. .IP \(bu 4
  218. Type: Path
  219. .RE 0
  220. .P
  221. When publishing, the provenance bundle at the given path will be used.
  222. .P
  223. This config cannot be used with: \fBprovenance\fR
  224. .SS "See Also"
  225. .RS 0
  226. .IP \(bu 4
  227. npm help "package spec"
  228. .IP \(bu 4
  229. \fBnpm-packlist package\fR \fI\(lahttp://npm.im/npm-packlist\(ra\fR
  230. .IP \(bu 4
  231. npm help registry
  232. .IP \(bu 4
  233. npm help scope
  234. .IP \(bu 4
  235. npm help adduser
  236. .IP \(bu 4
  237. npm help owner
  238. .IP \(bu 4
  239. npm help deprecate
  240. .IP \(bu 4
  241. npm help dist-tag
  242. .IP \(bu 4
  243. npm help pack
  244. .IP \(bu 4
  245. npm help profile
  246. .RE 0