← All notes

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

Patterns and rules

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

Sources

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

Permanent ID: iil:note:krgbv0gy

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.},
}

Markdown

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.

All artifact files (JSON index)

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.