Skip to content

Conversation

@fraidev
Copy link
Contributor

@fraidev fraidev commented Dec 19, 2025

Closes #29123
Related denoland/deno_core#1149

Needs:

When a module with Top-Level Await (TLA) is dynamically imported multiple times before the TLA resolves, subsequent imports would fail with "Cannot access 'default' before initialization".

This happened because V8 sets module status to Evaluated immediately after calling module.evaluate(), even when TLA is pending. Deno would see Evaluated status and try to resolve immediately, exposing uninitialized bindings (TDZ violation).

The fix queues subsequent import resolvers in pending_tla_waiters when a module has pending TLA, and resolves them all when the TLA promise completes.

@fraidev fraidev changed the title Fix/dynamic import pending tla fix: queue dynamic imports for modules with pending TLA Dec 19, 2025
@fraidev fraidev marked this pull request as ready for review December 19, 2025 04:33
@fraidev fraidev changed the title fix: queue dynamic imports for modules with pending TLA fix: queue dynamic imports for modules with pending TLA [Draft] Dec 19, 2025
@fraidev fraidev force-pushed the fix/dynamic-import-pending-tla branch from afaa69c to 06f1ff3 Compare January 5, 2026 14:52
@fraidev fraidev requested a review from bartlomieju January 5, 2026 14:53
@fraidev fraidev changed the title fix: queue dynamic imports for modules with pending TLA [Draft] fix: queue dynamic imports for modules with pending TLA Jan 7, 2026
@fraidev fraidev merged commit cfceaa8 into denoland:main Jan 7, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

import an mjs file twice at the same time cause an error

2 participants