---
source: https://iinventedlight.com/library/notes/node-subpath-imports.md
title: "The package.json imports field creates private #-prefixed module aliases inside a Node package"
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 subpath imports"
tags: [node, package-json, imports, subpath-imports, aliases, esm]
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 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

```json
{
  "imports": {
    "#internal/*.js": "./src/internal/*.js",
    "#dep": { "node": "dep-node-native", "default": "./dep-polyfill.js" }
  },
  "dependencies": { "dep-node-native": "^1.0.0" }
}
```

```js
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 `#dep` does with `dep-node-native` above.
- Conditions work here too: in other environments `import '#dep'` gets the local file `./dep-polyfill.js` relative 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

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

## 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.

---

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