Skip to content

esm: allow `--import` to define main entry

This PR changes the behavior of node --import ./entry.js from running entry.js and then launching the REPL; to running entry.js as the main entry point. This is a semver-major change; to preserve the prior behavior, the user must additionally pass -i or --interactive, so like node --import ./entry.js --interactive.

There are a few reasons for this change in behavior:

  • It provides a way to run a URL as the main entry point, because the values of --import are parsed as URLs. Users can run node --import ./entry.js?foo=bar or node --import data:text/javascript,console.log("Hello").

  • It provides a way to run a bare specifier as the main entry point, for example node --import typescript-repl.

This satisfies the “define the main entry point as a URL” part of https://github.com/nodejs/node/issues/49432.

Since this is a semver-major change, it cannot be backported. node --import ./entry.js?foo=bar --eval '' can achieve very similar results in current and past versions of Node. See also https://github.com/nodejs/node/issues/49432#issuecomment-1739626273. @nodejs/loaders

Merge request reports

Loading