Modules, Runtime & Tooling

Publishing Packages

Publishing a JS/TS package means defining runtime entrypoints, type entrypoints, dependency boundaries, exports, files, versioning, compatibility, and consumer expectations.
  • Package exports define the public surface
  • Declarations must match emitted JavaScript
  • Peer dependencies express host-provided packages
  • Files should be intentionally published
  • Semver is a communication tool
ESM package entrypoint
{
  "name": "@acme/utils",
  "version": "1.0.0",
  "type": "module",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js"
    }
  },
  "files": ["dist"]
}
The package declares both runtime and type entrypoints.
Publishing checklist
ConcernQuestion
EntrypointsWhat can consumers import?
TypesDo declarations match emitted JS?
DependenciesWhich packages are runtime, dev, peer?
FilesWhat actually gets published?
Module formatESM, CJS, or both?
VersioningIs this change breaking?
Consumer testsDid a real consuming project import it?
Sources
  • npm DocumentationPublishing packages
  • The TypeScript HandbookPublishing declaration files
  • Node.js Documentation and Learn Node.jsPublishing a package