esm: Modify ESM Experimental Loader HooksΒ #34753
Copy link
Copy link
Closed as not planned
Labels
discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
This issue is regarding #34144 . The original proposal on that PR was to modify the getSource loader hook to be able to optionally return a format in its return object that overrides the format returned by getFormat.
This method was eventually discussed at a team meeting: nodejs/modules#536 and a new proposal was eventually brought up: remove the getFormat hook entirely.
I plan to explore this option and submit a PR in the coming 2 weeks.
cc: @jkrems @nodejs/modules-active-members
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
discussIssues opened for discussion and feedback.Issues opened for discussion and feedback.esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Activity
hybrist commentedon Aug 12, 2020
cc @nodejs/modules-active-members with my special ping powers.
MylesBorins commentedon Oct 7, 2020
Removing agenda label. Please re-add if there is more for us to discuss in the meeting
lostpebble commentedon Nov 30, 2020
Just thought I'd drop by to say I've run into a bit of a wall today, which I think these coming changes would have been very helpful for:
I actually tried returning
format: "commonjs"without knowing that it doesn't actually work- just assumed it might. So it does feel like a natural API to me.I also ran into some issues with Node not being able to recognize relative TypeScript imports without an extension, for example:
I tried to intercept the imports with the
resolvehook, and rewrite them. But didn't seem to get it right. Would be nice if this was made a little easier too- perhaps with arecognizedModuleExtensions: []option or something. But that's probably not completely relevant to this issue.hybrist commentedon Nov 30, 2020
I think at the least we should issue a warning when a source is provided with
format=commonjs, with or without this PR. Because of the async nature of the ESM system, we'd likely be unable to use the result in a "real" require (from CJS) and we wouldn't want to risk a race condition betweenrequireandimportof the same file.But you bring up a good general point - we should document how to write a transform that can handle both CJS and ESM.
github-actions commentedon Jun 27, 2026
This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
github-actions commentedon Jul 28, 2026
This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.