Esc
  • Jump to
  • The board
  • All launchesSort and filter by week or category
  • Open statsEvery number, in public
  • Maker storiesApps that stopped hiding
  • Submit a launch
  • AICategory
  • AnalyticsCategory
  • API & BackendCategory
  • Audio & VoiceCategory
  • AutomationCategory
  • CommunityCategory
↑↓ to move↵ to openPress / anywhere
Sign in

How to Launch an npm Package (2026)

Choose a clean package name, ship dual ESM and CJS with TypeScript types, publish with OIDC Trusted Publishers and provenance, and drive real developer installs.

By Pritam Ghosh, founder of HauntboardUpdated 6 min read

Naming Your Package and Configuring package.json

Publishing to npm takes one command, so many first releases ship with broken imports, missing types or stray test fixtures in the tarball. Getting your package name and package.json right before version one avoids painful breaking migrations later.

Scoped vs unscoped names

Packages are either unscoped (for a made-up date helper, parse-window) or scoped to a user or organization (@acme/parse-window). Per npm's Package name guidelines and package.json docs, names must be 214 characters or fewer (including the scope), lowercase only, URL-safe and free of trademark conflicts. Avoid core Node.js module names and redundant js or node suffixes. Unscoped names cannot begin with a dot or underscore or mimic existing packages.

Unscoped names are shorter to type, while scoped names guarantee availability and group related packages cleanly. Under npm's scoped public packages guide, scoped packages default to private visibility, so pass npm publish --access public on your first publish or set "publishConfig": { "access": "public" }.

Key package.json fields

  • exports and types: define your public entry points, block accidental deep imports into internal files, and point TypeScript to your declaration files.
  • files: allowlists files packed into the tarball (for example ["dist"]); omitting it defaults to ["*"]. Per the npm publish docs, package.json, README, LICENSE, main and bin are always included while .git, node_modules, .npmrc and lockfiles are excluded by default. Always inspect the tarball with npm pack --dry-run first.
  • sideEffects: per webpack's tree-shaking guide, set "sideEffects": false for pure libraries (or list side-effectful globs like ["*.css"]) so bundlers can prune unused exports safely.
  • repository, license, keywords and engines: match repository.url exactly to your GitHub or GitLab repo (required for provenance and Trusted Publishers), set an SPDX license, and declare your supported Node.js range.

Shipping ESM, CommonJS and TypeScript Declarations

Module resolution bugs cause more day-one issues than runtime code. Choose ESM-only ("type": "module") if your users run modern Node.js LTS and bundlers, or ship dual ESM and CommonJS if teams still load libraries via require().

For dual builds, follow Node.js's Conditional exports guide. Map "import" and "require" to separate .mjs and .cjs entry points from most specific to least specific with "default" last, keeping a top-level "main" fallback for older tools.

Per TypeScript's Declaration Files Publishing guide, bundle .d.ts declarations inside your package via "declaration": true (emitting matching .d.mts and .d.cts files for dual packages) whenever you own the source. And per TypeScript's Modules Reference, condition order is strict:

  • Put "types" first inside each branch of exports (for example "import": { "types": "./dist/index.d.mts", "default": "./dist/index.mjs" } and the same for "require"). If JavaScript matches before "types", TypeScript falls back to any.
  • List any external @types/* packages exposed in your public types under dependencies (not devDependencies), and omit /// <reference path="..." /> directives.
  • Test the real tarball locally by running npm pack and installing the .tgz into separate ESM and CommonJS scratch projects with TypeScript strict mode enabled.

Trusted Publishers (OIDC), Provenance and 2FA

Modern npm releases replace long-lived publish secrets with short-lived CI identity tokens. Compare the three publish methods:

MethodAuthenticationBest fitProvenance
Trusted Publishers (OIDC)Short-lived CI identity tokenGitHub Actions, GitLab CI or CircleCI releasesAutomatic on GitHub Actions and GitLab CI (public repos)
Granular Access TokenScoped, expiring token from npmjs.comRead-only private installs or unsupported CINeeds --provenance on supported CI
Local publish + 2FAInteractive login + security key / OTPInitial setup or manual stage approvalsNot available locally

Follow npm's Trusted publishing guide for automated CI. It requires npm CLI 11.5.1+ and Node.js 22.14.0+ on cloud-hosted runners for GitHub Actions, GitLab CI/CD or CircleCI (self-hosted runners are not yet supported):

  1. Add the trusted publisher on npmjs.com: under package Settings > Trusted publishing (up to 10 per package), enter your case-sensitive GitHub org/user, repo name, workflow filename (just publish.yml, not the full path), optional environment and allowed actions (npm stage publish, npm publish or npm dist-tag). Complete your first publish within 2 days or the unvalidated config expires.
  2. Configure GitHub Actions: set permissions: id-token: write and contents: read, run on ubuntu-latest, pass registry-url: 'https://registry.npmjs.org' with package-manager-cache: false, match package.json's repository.url to your repo, and run npm publish with no static NPM_TOKEN.
  3. Ship automatic provenance: per npm's provenance docs, publishing a public package from a public repo via GitHub Actions or GitLab CI Trusted Publishers automatically signs Sigstore provenance attestations into the public transparency log (no --provenance flag needed; CircleCI and private repos do not currently emit provenance). Consumers verify with npm audit signatures.
  4. Harden 2FA and tokens: under npm's 2FA policy, publishing requires 2FA (security keys or biometrics, defaulting to authorization and writes) or a bypass-2FA granular token (since August 2026, bypass-2FA tokens cannot run account-identity or governance actions). Once OIDC works, set Publishing access to Require two-factor authentication and disallow tokens (OIDC still runs), revoke old write tokens, or use stage-only CI (npm stage publish) requiring 2FA approval. If CI installs private dependencies, issue a read-only granular access token on npmjs.com with an expiration date (at least 1 day ahead), scoped to needed packages (up to 50) and optional CIDR IP rules.

Semantic Versioning, Dist-Tags and Unpublish Rules

Version numbers are a compatibility contract. Follow Semantic Versioning 2.0.0:

  • 0.1.0 vs 1.0.0: use 0.y.z during rapid early iteration; release 1.0.0 once teams depend on a stable public API.
  • MAJOR.MINOR.PATCH: bump PATCH for backward-compatible fixes, MINOR for backward-compatible features or deprecations, and MAJOR for breaking changes (always deprecate in a minor release before removing in a major).
  • Pre-releases and dist-tags: ship release candidates like 2.0.0-rc.1 with npm publish --tag next so normal installs stay on latest. (OIDC dist-tag commands require npm CLI 11.21.0+ or 12.2.0+ with Allow npm dist-tag enabled.)

Document each release clearly using our guide on how to write a changelog. Also remember npm's Unpublish Policy: published version numbers are permanently immutable and can never be reused. You can only unpublish within 72 hours if no public packages depend on yours, or after 72 hours only with zero dependents, under 300 weekly downloads and a single maintainer (and unpublishing every version blocks new publishes for 24 hours). Otherwise, run npm deprecate <pkg>@<version> "reason" and publish a fixed patch.

README Quick Start and Developer Distribution

Your README.md is your npmjs.com product page. Put four items above the fold: one plain sentence stating the problem solved, the install command, a runnable code snippet with its real output, and links to docs, types and your license. For licenses, GitHub topics and contributor files, follow our open-source launch guide, and check your repo's share preview with the OG image previewer.

Registry search alone rarely brings early adopters. Launch where developers evaluate new libraries:

  • Show HN: read our Show HN review and Show HN post guide, link your repo or live playground, and post a factual first comment explaining trade-offs and bundle size.
  • Subreddits and newsletters: share technical write-ups in JavaScript, TypeScript or Node.js communities (following subreddit rules, see how to launch on Reddit) and submit notable releases to curated JavaScript weekly newsletters.
  • Developer launch boards: list your docs or repo on DevHunt and Hauntboard. On Hauntboard, a person reviews every launch (free launches in about 72 hours, paid options within 24 hours), new listings spend 7 days in New this week before joining the all-time leaderboard, and page views, visits sent and votes stay public.
release post template
"Shipped package-name v1.0.0 on npm: a size/zero-dep TypeScript library for specific task. Install with npm i package-name. Built it because existing alternative struggled with specific pain point. Ships ESM + CJS with bundled types and npm provenance. Repo and runnable examples: URL"

Frequently Asked Questions

Once npm pack --dry-run is clean, your Trusted Publisher workflow is green and your README quick start runs from scratch, submit your npm package on Hauntboard alongside Show HN and DevHunt.

Should I publish my package as scoped or unscoped?

Pick unscoped if a short, clear name is free for a standalone library. Pick scoped (@org/pkg or @username/pkg) if the unscoped name is taken or you plan a suite of packages, and pass --access public on the first publish.

Do I need an npm access token in GitHub Actions to publish?

No. npm Trusted Publishers (OIDC) authenticates GitHub-hosted runners automatically when your workflow sets id-token: write on npm CLI 11.5.1+ and Node.js 22.14.0+. You only need a read-only granular token if CI installs private npm dependencies.

Can I overwrite or delete a broken npm version after publishing?

Never overwrite. You can unpublish within 72 hours if no public packages depend on it, or after 72 hours only with zero dependents, fewer than 300 weekly downloads and one maintainer. Even then, that version number stays retired, so npm deprecate plus a patch release is usually safer.

Why does TypeScript ignore my types when I add an exports field?

TypeScript evaluates conditional exports from top to bottom and stops at the first match. Always place "types" first inside each "import" and "require" branch so TypeScript resolves your .d.mts or .d.cts file before the JavaScript entry point.

Share

in

Pritam Ghosh runs Hauntboard and writes these guides.

Published · Updated

Got no audience? Start here.

A person reviews every launch, and every view and visit it gets is public. Launching is free.

Launch free →

Keep reading

All guides →

On the board

All →

Still hiding your app?

Put it on the board. Reviewed by a person, free to launch.

Launch free
Submit a launch