What this thread does
Do first: inspect the package's exports map and compare both import and require entry points against the files actually included in its distribution.
Short answer
As of November 2026, the reference runtime is Node.js 26.13.1, November 11. The support table also lists Node 22 and 24 as LTS; include each line the package promises. Conditional exports select entry files, while type determines how .js files are interpreted. Do not assume an import condition makes a .js target ESM (publishing guide).
Choose / don't choose
- CommonJS core plus ESM wrapper: choose when both consumer types must share constructor identity; don't duplicate the implementation just to provide named ESM imports (official dual-package example).
- Separate builds: choose for stateless code or deliberately isolated/shared state; don't ship two independent singleton registries. nicolo-ribaudo's March 21, 2024 report describes Babel's object-identity constraint and another conditional-export strategy.
- ESM-only: choose only after removing the CommonJS support promise; don't direct supported synchronous consumers into an asynchronous ESM graph.
Not for: fixing a dependency-owned ERR_REQUIRE_ESM import; see node-err-require-esm-require-of-es-module-package.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
exports.import | ./wrapper.mjs for the shared-core strategy | Historical Node dual-package example | dual-package example |
exports.require | ./index.cjs pointing to the same core the wrapper imports | Historical Node dual-package example | dual-package example |
type and output suffixes | "module" for ESM .js; "commonjs" for CJS .js; .mjs is ESM and .cjs is CJS regardless | Node 26.13.1 | package interpretation |
exports["."] / public subpaths | Declare the root and each supported subpath; targets start ./ | Node 26.13.1 | package exports |
Nested import.types / require.types | Format-specific .d.mts and .d.cts; types condition first in exports | TypeScript 4.7+ Node resolution | 4.7 declaration contract |
module, moduleResolution | Pair NodeNext/NodeNext for direct Node consumers; node16 resolution where that compatibility contract is intentional | Consumer's locked TypeScript | module reference |
For dual declaration branches, use import: { types: './types/esm/index.d.mts', default: './wrapper.mjs' } and require: { types: './types/commonjs/index.d.cts', default: './index.cjs' } under the root export. These are authored distribution paths following the TypeScript contract; actually emit and include those files. Each declaration's format must match its corresponding runtime entry, even if the exposed API appears identical. A single declaration file cannot generally represent both module formats (TypeScript 4.7).
Order of operations
1. Define public root/subpaths and promised Node versions, then build the runtime files and declarations. Adding exports encapsulates unlisted old deep imports; preserve intentional public ones or treat removal as an API change (Node). 2. For a shared core, the wrapper imports ./index.cjs once and explicitly re-exports its intended named/default API. This avoids relying on heuristic CJS named-export discovery (publishing guide). 3. Inspect the packed distribution, install it into separate ESM and CJS consumer fixtures, then import the package name and each public subpath. Include both fixture builds in the package release gate. 4. Type-check .mts and .cts consumers with their compatible Node resolution modes; include bundler only for supported bundler consumers, paired with a supported module such as preserve. Run both import styles together in one process and compare the promised singleton/constructor identity (module reference, dual-package example).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
ERR_PACKAGE_PATH_NOT_EXPORTED | Requested subpath is not exported | Add the intended public subpath/condition or change the caller to the public entry; rebuild and include its target | Node exports |
ERR_REQUIRE_ASYNC_MODULE | A require-selected ESM graph contains top-level await | Route promised synchronous CJS consumers to the .cjs implementation; do not label an async ESM graph module-sync | Node conditions |
The require condition matches loading via require(), and ordered condition objects should put default last. The module-sync condition also matches require(), so ERR_REQUIRE_ESM is not a universal result for every ESM dependency. The wrapper strategy avoids depending on that newer interop for the CommonJS promise.
Missing
- No package support policy or output inventory is given; select exact patch versions within every promised runtime line and confirm the distributed files. A runtime-only import check does not establish declaration compatibility.
Checked
2026-11-12; Node 26.13.1; conditional exports unflagged in 12.17/13.7; declaration module kind must match its JavaScript file. Sources read: Node release/support/package/publishing pages, official dual-package examples, TypeScript notes/reference and nicolo-ribaudo's issue. No package builds or consumer commands were run.
Started from a post by @Node.js, packaged by the editor. Original post