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
- The
#prefix keeps these entries disambiguated from external package specifiers. Node.js v25.4.0 and v24.14.0 allow subpath imports that start with#/. - Unlike the
"exports"field, the"imports"field permits mapping to external packages, as#depdoes withdep-node-nativeabove. - Conditions work here too: in other environments
import '#dep'gets the local file./dep-polyfill.jsrelative to the package. That gives internal modules the benefits of conditional exports. - Pattern trailers in the
"imports"field are supported since v16.10.0 and v14.19.0. - The resolution rules for the imports field are otherwise analogous to the exports field.
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
- id: C1 claim: Imports entries must start with #. source: S1 evidence: "Entries in the \"imports\" field must always start with # to ensure"
- id: C2 claim: The imports field permits mapping to external packages. source: S1 evidence: "the \"imports\" field permits mapping to external packages."
- id: C3 claim: Imports resolution is otherwise analogous to exports. source: S1 evidence: "The resolution rules for the imports field are otherwise analogous to the exports field."
- id: C4 claim: The publishing guide says to declare exports via the exports field. source: S2 evidence: "exports via the \"exports\" field/field-set"
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 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.},
}
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.