exports field
The package.json field that lists exactly which files a package exposes, by path such as "." or "./button", and which file to use in each situation.
In more detail
Anything not listed cannot be imported, which keeps internal files private. Each path can map conditions such as types, import and require to different files. It replaces the older main and module fields for modern tools.
Example
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.mjs", "require": "./dist/index.cjs" } }Related terms
- export condition — A key inside an exports entry, such as types, import, require or default, that says which environment should get which file.
- package.json — The JSON file at the root of every JavaScript package that records its name, version, dependencies, entry points and other settings.
- dual package — A package that ships both an ECMAScript module build and a CommonJS build, choosing between them through export conditions.
- package entry point — A path consumers can import from a package, such as @company/design or @company/design/button, each mapped to its own files.
Taught in
- Component Packaging: Dual ESM/CJS Builds & Package Exports — Design Systems & Component Engineering