Before You Run npm publish: An Eighteen-Item Checklist
Publishing to npm is a single command, which is exactly why it goes wrong. A version, once published, can only be unpublished under the registry's restrictive policy, so the time to catch a mistake is before the command, not after. Work through these items in order; each has one line saying why it is on the list.
Metadata in package.json
- [ ]
nameis the one you intend, scope included. A typo creates a new package that someone else could later be confused with. - [ ]
versionmatches the changelog heading and the tag you will push. Mismatches make bug reports impossible to place. - [ ]
licenseholds a valid SPDX identifier. Compliance tools read this field, not your LICENSE file. - [ ]
repositorypoints at the real source. Provenance checks and users following links both rely on it. - [ ]
engines.nodestates the oldest Node.js line you test. It documents your support promise, even where package managers only warn. - [ ] Dependencies are in the right bucket. Something your code imports at runtime in
devDependenciesworks locally and breaks for every user.
Tarball contents
- [ ] A
filesallow-list exists. Allow-lists fail safe; an.npmignorethat forgets one pattern leaks it. - [ ]
npm pack --dry-runoutput has been read line by line. It is the only authoritative list of what ships. - [ ] No
.env, keys, fixtures or coverage reports appear. Leaked credentials in published tarballs are a recurring incident type. - [ ] The build ran from a fresh clone. Stale files in
dist/from an old build get published silently.
Entry points and types
- [ ] Every path in
exports,mainandtypesexists in the tarball. A missing entry file is the classic "cannot find module" release. - [ ] The
exportsmap has a condition for each format you ship. Missingrequireorimportconditions break one half of your users. - [ ] Type declarations resolve for both import styles. Tools such as "Are the Types Wrong?" check this against the packed tarball.
- [ ] The tarball installs and imports in an empty project. Install the
.tgzfile directly, thenimportandrequireit.
npm pack
mkdir /tmp/try && cd /tmp/try && npm init -y
npm install /path/to/package-a-1.2.0.tgz
node -e "import('package-a').then(m => console.log(Object.keys(m)))"
Quality gates and the publish itself
- [ ] CI is green on the tagged commit across the test matrix. A green branch is not the same commit as the tag.
- [ ] The right dist-tag is set. Publishing a beta without
--tag nextmakes itlatestfor everyone. - [ ] Publishing runs from CI with provenance.
npm publish --provenancefrom a supported CI provider links the version to its build. - [ ] Two-factor authentication is on for the publishing account. It is the cheapest protection against a stolen password.
After publishing
Check the package page on the registry, then install the new version by name from a clean directory. If something is wrong, publishing a fixed patch is usually better than unpublishing; npm Docs describe the current unpublish rules, and the notes on npm's unpublish policy explain the background. Related reading: setting up the exports field, pre-release versions and dist-tags and the npm provenance explainer.