Closed as duplicate of#57226
Description
Currently there is no equivalent of require.main
for ESM scripts.
Note that this is not listed at all in https://nodejs.org/api/esm.html#differences-between-es-modules-and-commonjs either.
The "known" equivalent would be to use process.argv[1] === new URL(import.meta.url).pathname)
, but it doesn't work with symbolic links (e.g. npm bin scripts).
A solution is to use https://www.npmjs.com/package/es-main, which practically goes down to require
to implement it. I think we should really include something out of the box.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Awaiting Triage