Repository navigation
Provide SourceTextModule sync versions of link and evaluate methods #59656
Copy link
Copy link
Closed
Copy link
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Description
Activity
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
on Aug 27, 2025 The synchronous linking method is implemented in #59000
I am not sure if evalauteSync is entirely necessary - evaluation is already synchronous if the module does not contain a top-level await and the returned promise would be synchronously fulfilled with undefined, as specified in ECMA262 (in this case, the promise is just like a maybe, you can just assume that it's already fulfilled in synchronous code).
Reacted by Mikhail and Chengzhong Wu- linked a pull request that will close this issuevm: sync-ify SourceTextModule linkage #59000
on Aug 29, 2025 I think to be able to implement userland
require(esm)on top ofvm.SourceTextModule, there must be a way to detect if the module graph is async (like, if it and its dependencies contain TLA or not), so that a userland framework can do:function requireEsm() { const mod = new vm.SourceTextModule(...); mod.linkRequests(mod.moduleRequests.map(resolve)); mod.instantiate(); // This is missing if (mod.isGraphAsync) { throw new Error('Module graph is async'); } mod.evaluate(); if (mod.status === 'errored') { throw mod.error; } return mod.namespace; }
Reacted by Joyee Cheung- addedvmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
on Aug 29, 2025 - added a commit that references this issue
on Sep 19, 2025 - added 2 commits that reference this issue
on Sep 23, 2025 - added 2 commits that reference this issue
on Oct 18, 2025 - added 2 commits that reference this issue
on Oct 23, 2025 - added 4 commits that reference this issue
on Feb 17, 2026
Metadata
Metadata
Assignees
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Type
Projects
- StatusShow more project fieldsAwaiting Triage
What is the problem this feature will solve?
Allow to reimplement require(esm) logic with custom require. Current logic in jest covers only require(cjs) and native modules and to support require(esm) there is need of SourceTextModule sync version with sync link and evaluate methods.
jestjs/jest#15275
What is the feature you are proposing to solve the problem?
linkSyncandevaluateSyncmethods forSourceTextModuleor another sync way to programmaticaly create and initialize module.What alternatives have you considered?
Customization hooks but looks like, according to #56241, there is fundamental problem with implementing evaluation hook for esm modules.