node/lib/internal/modules/cjs
Joyee Cheung c1e7fa2586
module: handle .mjs in .js handler in CommonJS
This refactors the CommonJS loading a bit to create a center point
that handles source loading (`loadSource`) and make format detection
more consistent to pave the way for future synchronous hooks.

- Handle .mjs in the .js handler, similar to how .cjs has been handled.
- Generate the legacy ERR_REQUIRE_ESM in a getRequireESMError() for
  require(esm) handling (when it's disabled).

PR-URL: https://github.com/nodejs/node/pull/55590
Backport-PR-URL: https://github.com/nodejs/node/pull/59504
Refs: https://github.com/nodejs/loaders/pull/198
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Refs: https://github.com/nodejs/node/issues/52697
2025-08-27 19:20:42 +02:00
..
loader.js module: handle .mjs in .js handler in CommonJS 2025-08-27 19:20:42 +02:00