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
{
"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 viaimportorimport();"require"matches when it is loaded viarequire(). 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 asfeatures/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
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.
License: CC-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.
Cite this
iinventedlight. 2026. "The package.json exports field defines a Node package's public entry points and conditions." iinventedlight Library, iil:note:krgbv0gy, version of 2026-11-18. https://iinventedlight.com/library/notes/node-package-exports/. License: CC-BY-4.0.
@misc{iil_note_krgbv0gy,
author = {{iinventedlight}},
title = {{The package.json exports field defines a Node package's public entry points and conditions}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/node-package-exports/},
note = {Permanent ID iil:note:krgbv0gy. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- node-package-exports.table.json (table; CC-BY-4.0)
- node-package-exports.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-package-exports.md.