Node.js & npm ReferenceUpdated: 2026-11-06

package.json Schema, Modern Exports Maps & npm CLI Reference

Essential lookup for peerDependencies, subpath exports, ESM vs CJS conditional maps, sideEffects, and semver range rules.

The package.json manifest file is the foundational blueprint of every Node.js and TypeScript project. Modern Node.js versions require conditional exports maps for dual CommonJS and ESM packaging, strict engines specification, and optimized bundle sideEffects treeshaking.

Modern Conditional Exports Map (ESM & CJS Dual Bundles)

The standard package.json exports field replacing the legacy main and module fields.

Condition KeyEnvironment MatchTarget Asset
`types`TypeScript compiler lookup (MUST be listed first)`./dist/index.d.ts`
`import`ES Module runtime (`import ... from "pkg"`)`./dist/index.mjs`
`require`CommonJS runtime (`const pkg = require("pkg")`)`./dist/index.cjs`
`default`Fallback for all other module loaders`./dist/index.js`

Dependency Categories & When to Use Which

Understanding how npm and pnpm resolve packages in production and consumption.

Category KeyBundled in Prod?Intended Package Type
`dependencies`YesCore libraries required for production execution (e.g. react, next, express)
`devDependencies`NoCompilers, linters, testing suites (e.g. typescript, jest, eslint, tailwindcss)
`peerDependencies`Host InstalledPlugin architectures requiring consumer to supply host (e.g. react in UI component libs)
`optionalDependencies`If AvailablePlatform-specific native binary bindings (e.g. @rollup/rollup-linux-x64-gnu)

SemVer Version Prefix Match Rules

How package versions resolve on `npm update` or fresh `npm install`.

Symbol PrefixVersion Range BehaviorGiven "1.2.3", Allows
`^` (Caret)Allows MINOR and PATCH updates (no breaking changes)>= 1.2.3 and < 2.0.0
`~` (Tilde)Allows PATCH updates only>= 1.2.3 and < 1.3.0
Exact (No prefix)Pins strictly to specified versionOnly 1.2.3
`*` (Wildcard)Always pulls the latest published releaseAny version (Dangerous in prod)

Frequently Asked Questions

What does "sideEffects": false do in package.json?

It informs webpack, Vite, and Rollup that no files in the package contain code that executes merely upon import (like modifying global prototypes or injecting CSS). This enables bundlers to aggressively tree-shake and discard 100% of unused exported modules.

What is the purpose of npm clean-install (npm ci)?

`npm ci` strictly installs dependencies based on `package-lock.json` without updating it, deleting existing node_modules first. It is significantly faster and deterministic, making it mandatory for CI/CD deployment pipelines.