← All notes

The package.json imports field creates private #-prefixed module aliases inside a Node package

Answer: Use the package "imports" field, with entries that start with #. These private mappings only apply to import specifiers from within the package itself.

Example

{
  "imports": {
    "#internal/*.js": "./src/internal/*.js",
    "#dep": { "node": "dep-node-native", "default": "./dep-polyfill.js" }
  },
  "dependencies": { "dep-node-native": "^1.0.0" }
}
import internalZ from '#internal/z.js'; // Loads ./src/internal/z.js
import dep from '#dep';

Rules

History

The "imports" field was added in v14.6.0 and v12.19.0. Node.js v12.7.0 introduced the "exports" field as a more powerful alternative to the classic "main" field.

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:7vwk4r2a

iinventedlight. 2026. "The package.json imports field creates private #-prefixed module aliases inside a Node package." iinventedlight Library, iil:note:7vwk4r2a, version of 2026-11-18. https://iinventedlight.com/library/notes/node-subpath-imports/. License: CC-BY-4.0.

@misc{iil_note_7vwk4r2a,
  author = {{iinventedlight}},
  title = {{The package.json imports field creates private \#-prefixed module aliases inside a Node package}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/node-subpath-imports/},
  note = {Permanent ID iil:note:7vwk4r2a. 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).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-subpath-imports.md.