Node.js Module Resolution & ESM/CJS Interop

Parent: JavaScript and Node.js · researched 2026-06-02T18:02:36.400Z· 7 sources · 8 concepts · skill nodejs-module-resolution

This reference is about HOW Node.js turns a specifier into a loaded module — the two

Overview

1. The CommonJS `require(X)` resolution algorithm

2. The ESM resolution algorithm

3. `package.json` `"exports"` — conditional exports, subpaths, patterns, encapsulation

4. `package.json` `"imports"` — private `#` internal specifiers

5. The dual-package hazard

6. ESM ↔ CJS interop: `require(esm)`, importing CJS, `createRequire`

7. Module customization (loader) hooks

8. Import attributes, JSON modules, and import maps

Methodology — practical patterns

Anti-patterns

Troubleshooting

References

Children

Frontier under this node: ESM <-> CJS interop: require(esm), importing CJS, createRequire, Import attributes, JSON modules, and import maps, Module customization (loader) hooks (module.register / registerHooks), The CommonJS require(X) resolution algorithm, The ESM resolution algorithm (ESM_RESOLVE), The dual-package hazard, package.json exports — conditional exports, subpaths, patterns, encapsulation, package.json imports — private #internal specifiers

← the whole tree · 3D view· how to read this page