A package.json Template for a Library

Application manifests and library manifests look alike but serve different readers. An application's package.json is read by its own build; a library's is read by every package manager, bundler, type checker and security scanner that touches it. This template is a reasonable baseline for a TypeScript library that ships both ESM and CommonJS. Replace the placeholders and delete what you do not need.

The template

{
  "name": "@scope/package-name",
  "version": "0.1.0",
  "description": "One sentence saying what the package does.",
  "license": "MIT",
  "author": "Your Name",
  "repository": {
    "type": "git",
    "url": "git+https://example.invalid/owner/package-name.git"
  },
  "type": "module",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js",
      "require": "./dist/index.cjs"
    },
    "./package.json": "./package.json"
  },
  "main": "./dist/index.cjs",
  "types": "./dist/index.d.ts",
  "files": ["dist"],
  "sideEffects": false,
  "engines": { "node": ">=20" },
  "scripts": {
    "build": "your-build-command",
    "test": "your-test-command",
    "prepack": "npm run build"
  },
  "peerDependencies": {},
  "dependencies": {},
  "devDependencies": {}
}

The repository URL is a placeholder; point it at your real source so that provenance and "view source" links work.

Why each field is there

FieldReason
licenseAn SPDX identifier that licence scanners read directly.
typeMakes .js files ESM; the CommonJS build uses .cjs to stay unambiguous.
exportsDefines the public entry points and blocks deep imports. types comes first because conditions match in order.
"./package.json" exportSome tools read a dependency's manifest; exporting it avoids errors for them.
main, typesFallbacks for tools that predate exports.
filesAllow-list of what ships; everything else stays out.
sideEffectsLets bundlers drop unused modules. Use an array if some files do have side effects.
enginesStates the oldest Node.js you test.
prepackBuilds automatically before npm pack and npm publish, so stale output is not shipped.

Simplifying it

A filled example (illustrative)

A hypothetical @example/slugify package would set "name": "@example/slugify", "description": "Turn titles into URL slugs.", keep the dual build, set engines.node to the oldest line in its CI matrix, and list nothing under dependencies. That last point is worth aiming for: each dependency you add becomes something your users also install and audit. Scoped packages publish as private by default on npm, so the first publish needs npm publish --access public; the scoped packages notes explain more.

Check the result with the npm pre-publish checklist and, for the exports block in detail, the exports field how-to.