-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Closed as duplicate of#57226
Labels
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
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
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Type
Projects
Status
Awaiting Triage