Skip to content

module: enable existing machinery for deferred imports#63712

Open
MayaLekova wants to merge 1 commit into
nodejs:mainfrom
MayaLekova:import-defer-01
Open

module: enable existing machinery for deferred imports#63712
MayaLekova wants to merge 1 commit into
nodejs:mainfrom
MayaLekova:import-defer-01

Conversation

@MayaLekova

Copy link
Copy Markdown
Contributor

This commit enables deferred module imports by using the corresponding functionality in V8. It also adds a single test, but more test coverage should be added.

Refs: https://github.com/tc39/proposal-defer-import-eval

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/vm

@MayaLekova MayaLekova changed the title module: enable existing machinery for import defer module: enable existing machinery for deferred imports Jun 2, 2026
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jun 2, 2026

@joyeecheung joyeecheung left a comment

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.

I think the commit message needs to clarify that this only makes it work for static import, but not dynamic import yet?

Comment thread test/fixtures/es-modules/module-deferred-eval.mjs
@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.35%. Comparing base (6813080) to head (6bb2db9).
⚠️ Report is 24 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #63712    +/-   ##
========================================
  Coverage   90.34%   90.35%            
========================================
  Files         732      732            
  Lines      236580   236709   +129     
  Branches    44545    44585    +40     
========================================
+ Hits       213748   213870   +122     
- Misses      14536    14565    +29     
+ Partials     8296     8274    -22     
Files with missing lines Coverage Δ
src/module_wrap.cc 74.41% <100.00%> (+0.04%) ⬆️
src/module_wrap.h 52.94% <ø> (ø)

... and 53 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MayaLekova

Copy link
Copy Markdown
Contributor Author

Thank you, I moved the test, but should I add more extensive test coverage, even for static imports?

@joyeecheung

joyeecheung commented Jun 4, 2026

Copy link
Copy Markdown
Member

I think a smoke test is enough. The rest should be covered by test262 in the upstream.

Can you rewrap the commit message to 72 chars to make the linter happy? Also this needs adding a eslint plugin

2026-06-03T13:01:48.8039114Z /home/runner/work/node/node/test/es-module/test-defer-import-eval.mjs
2026-06-03T13:01:48.8044324Z 10:7 error Parsing error: This experimental syntax requires enabling the parser plugin: "deferredImportEvaluation". (10:7)

@mcollina mcollina left a comment

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.

Amazing!

@MayaLekova MayaLekova force-pushed the import-defer-01 branch 3 times, most recently from 2915765 to bd9968c Compare June 8, 2026 15:08
Comment thread src/module_wrap.h
This commit enables deferred import for statically imported modules,
by using the corresponding functionality in V8. It adds two tests:
 - smoke test exercising the basic syntax
 - test for deferred import of module with its own imports

More test coverage should be added for mixing ESM and CJS modules,
as well as TypeScript modules.

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

@guybedford guybedford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Works perfectly thank you!

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 9, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 9, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator


// Attempts to define a property on the deferred module. This should
// trigger its execution, similar to accessing the `foo` property.
assert.throws(() => Object.defineProperty(deferred, 'newProp', { value: 15 }), TypeError);

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.

Suggested change
assert.throws(() => Object.defineProperty(deferred, 'newProp', { value: 15 }), TypeError);
assert.throws(() => Object.getOwnPropertyDescriptor(deferred, 'newProp'), TypeError);

Linter is complaining that it's read-only, I think using the getter does what we want too anyway.


import '../common/index.mjs';

import defer * as deferred from '../fixtures/es-modules/module-with-module-tree.mjs'

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.

Suggested change
import defer * as deferred from '../fixtures/es-modules/module-with-module-tree.mjs'
import defer * as deferred from '../fixtures/es-modules/module-with-module-tree.mjs'
console.log(defer.bar);

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++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants