---
source: https://iinventedlight.com/library/notes/node-package-exports.md
title: "The package.json exports field defines a Node package's public entry points and conditions"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Node.js API docs); MIT (Node.js Learn); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Node.js API docs, Modules: Packages; Node.js Learn, Publishing a package. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: node package exports"
tags: [node, package-json, exports, conditional-exports, esm, commonjs]
client: Librarian
sources:
  - id: S1
    title: "Modules: Packages"
    publisher: Node.js API docs
    url: https://nodejs.org/api/packages.html
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "Publishing a package"
    publisher: Node.js Learn
    url: https://nodejs.org/en/learn/modules/publishing-a-package
    accessed: 2026-11-18
    license: "MIT"
---
# The package.json exports field defines a Node package's public entry points and conditions
**Answer:** List entry points in the `"exports"` field, with `"."` as the main entry point and `"./name"` keys for subpaths. Only the defined subpaths can be imported by a consumer; others throw `ERR_PACKAGE_PATH_NOT_EXPORTED`. Conditions such as `"import"`, `"require"`, `"node"` and `"default"` map to different files.

## Example

```json
{
  "name": "es-module-package",
  "type": "module",
  "exports": {
    ".": { "import": "./dist/esm/index.js", "require": "./dist/index.cjs" },
    "./submodule.js": "./src/submodule.js",
    "./features/*.js": "./src/features/*.js",
    "./package.json": "./package.json"
  }
}
```

## Conditions

- `"import"` matches when the package is loaded via `import` or `import()`; `"require"` matches when it is loaded via `require()`. The two are always mutually exclusive.
- `"node"` matches for any Node.js environment.
- `"default"` is the generic fallback that always matches and should always come last.
- Within the `"exports"` object, key order is significant: earlier entries have higher priority, so order conditions from most specific to least specific.
- The publishing guide notes an alternative: with `"node"` and `"default"` keys, Node.js will always choose the `"node"` option, which precludes the dual-package hazard.

## Patterns and rules

- `*` in a subpath pattern is a string replacement, so it can expose nested subpaths such as `features/y/y.js`. Including `"*.js"` on both sides restricts the exposed package exports to only JS files.
- All paths defined in `"exports"` must be relative file URLs starting with `./`.
- Within a package, any module can import its own exports by the package's name, and self-referencing is available only if package.json has `"exports"`.

## exports or main

`"exports"` prevents external access to internal code; if you don't need that, `"main"` is simpler. Including `"./package.json": "./package.json"` lets the file be imported.

## See also

- [node-subpath-imports](https://iinventedlight.com/library/notes/node-subpath-imports/)
- [node-esm](https://iinventedlight.com/library/notes/node-esm/)
- [node-commonjs-modules](https://iinventedlight.com/library/notes/node-commonjs-modules/)

## Claims

- id: C1
  claim: Undefined subpaths throw ERR_PACKAGE_PATH_NOT_EXPORTED.
  source: S1
  evidence: "// Throws ERR_PACKAGE_PATH_NOT_EXPORTED"

- id: C2
  claim: The default condition should always come last.
  source: S1
  evidence: "This condition should always come last."

- id: C3
  claim: Export paths must be relative file URLs starting with ./
  source: S1
  evidence: "must be relative file URLs starting with"

- id: C4
  claim: exports prevents external access to internal code.
  source: S2
  evidence: "because it prevents external access to internal code"

## Sources

- [S1] Modules: Packages. Node.js API docs. https://nodejs.org/api/packages.html . License: MIT. Accessed 2026-11-18.

- [S2] Publishing a package. Node.js Learn. https://nodejs.org/en/learn/modules/publishing-a-package . License: MIT. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js API docs, Modules: Packages; Node.js Learn, Publishing a package. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
