Skip to content

modules: implement deferred import for dynamic modules - #66727

Open
MayaLekova wants to merge 2 commits into
nodejs:mainfrom
MayaLekova:import-defer-06-dynamic-imports
Open

MayaLekova wants to merge 2 commits into
nodejs:mainfrom
MayaLekova:import-defer-06-dynamic-imports

Conversation

@MayaLekova

Copy link
Copy Markdown
Contributor

modules: implement deferred import for dynamic modules

This PR adds support for deferring the import of modules in additional
cases, such as importing a dynamic module. It also adds a test for
this case.

Refs: https://github.com/tc39/proposal-defer-import-eval
Signed-off-by: Maya Lekova maya@igalia.com

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/security-wg
  • @nodejs/startup
  • @nodejs/typescript
  • @nodejs/vm

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. esm Issues and PRs related to the ECMAScript Modules implementation. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. strip-types Issues and PRs related to TypeScript type stripping. labels Oct 14, 2026
@MayaLekova
MayaLekova force-pushed the import-defer-06-dynamic-imports branch from 2d077ed to f8ef554 Compare October 14, 2026 13:51
This PR adds support for deferring the import of modules in additional
cases, such as importing a dynamic module. It also adds a test for
this case.

Refs: https://github.com/tc39/proposal-defer-import-eval
Signed-off-by: Maya Lekova maya@igalia.com
@MayaLekova
MayaLekova force-pushed the import-defer-06-dynamic-imports branch from f8ef554 to 503ed1f Compare October 15, 2026 13:08
@MayaLekova

MayaLekova commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

I tried fixing the cctest failures, but apparently the change to ModuleWrap::Evaluate signature also changed the behaviour of the VM module. Still experiencing this error:

(node:50255) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/vm/module:215
      validateObject(options, 'options');
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "options" argument must be of type object. Received type number (-1)
    at SourceTextModule.evaluate (node:internal/vm/module:215:7)
    at /home/maya/Work/node/out/Release/cctest:1:328
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

@joyeecheung just FYI, I'll keep trying to fix it.

"});"
"await m.link(() => 0);"
"await m.evaluate();"
"await m.evaluate(-1, false, 3);"

@joyeecheung joyeecheung Oct 15, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the public API for the vm API, which is not used by the built-in loader at all, and it's not the same as the module wrap's evaluate, which is internal and used by both. There's no need to touch this.

@joyeecheung

Copy link
Copy Markdown
Member

Can you drop the amaro update commit? I don't think that's supposed to be in this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. esm Issues and PRs related to the ECMAScript Modules implementation. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. strip-types Issues and PRs related to TypeScript type stripping.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants