Skip to content

esm: bypass CommonJS loader under `--default-type=module`

This PR implements the part of https://github.com/nodejs/node/issues/49432 where we avoid using the CommonJS loader for ESM entry points in the new --default-type=module mode. This effectively completes some TODOs in the code that note that particular code paths should be deprecated.

The only user-observable effects of this are that, under --experimental-default-type=module:

  • Extension searching is no longer provided for the main entry point. Users need to type node entry.js, not node entry.
  • Libraries that were monkey-patching the CommonJS loader via code loaded by --require will no longer achieve anything. They weren’t achieving much before, as monkey-patching the CommonJS loader only affects CommonJS and not ES modules, so it’s not like the previous behavior was really working very well (if at all) for applications with an ESM entry point.

This inches us closer to actually deprecating the CommonJS loader and having the ESM loader handle all modules, which is a long term goal that will aid in maintainability and future functionality for the modules subsystem.

Merge request reports

Loading