The Node.js Module System: CommonJS vs ES Modules, "type", "exports" and require(esm)
Node.js loads a file as CommonJS or as an ES module based on its extension (.mjs/.cjs) and the "type" field in the nearest package.json; since require(esm) is stable in Node 26, the two worlds can now load each other, except for top-level await. With real errors: extensionless imports, ERR_REQUIRE_ASYNC_MODULE, named imports from CommonJS, paths closed by exports, the dual package hazard, and #-aliases plus JSON import attributes in the Bookstore API.
14 Nov 2026
·
11 min
·
8