Skip to content

fix(core): import() waits for a pending TLA of a static dependency - #37262

Open
phibar wants to merge 1 commit into
denoland:mainfrom
metatrom-ag:fix/dynamic-import-tla-static-dependency
Open

phibar wants to merge 1 commit into
denoland:mainfrom
metatrom-ag:fix/dynamic-import-tla-static-dependency

Conversation

@phibar

@phibar phibar commented Dec 2, 2026

Copy link
Copy Markdown

Fixes #37261
Related: #37259, #37260, #31670

A dynamic import() of a module that is still in its top-level await resolved early, with the namespace's bindings uninitialized (Cannot access 'default' before initialization), when that module was being evaluated as a static dependency of another dynamic import.

The fast path in load_dynamic_import detects a pending TLA by looking for the module in pending_dyn_mod_evaluations. That list only holds the root module of each dynamic import, so a dependency of it was never found there.

The fast path now also asks V8 for the module's evaluation promise. While that promise is pending, the import takes the regular load path, which already waits for it.

This is independent of #37260. It also makes the reproduction from #37259 pass on its own, since the check does not rely on pending_dyn_mod_evaluations.

Testing

AI disclosure

AI tools (Claude) were used to help write this change; it was reviewed by a human before submission.

The fast path in `load_dynamic_import` only knew a module had a pending
top-level await when the module was the root of a pending dynamic import.
A module still evaluating as a static dependency of one was not found
there, so `import()` handed out its namespace with the bindings
uninitialized ("Cannot access 'default' before initialization").

The fast path now asks V8 for the module's evaluation promise and, while
that is pending, takes the regular load path, which waits for it.

Fixes denoland#37261
@CLAassistant

CLAassistant commented Dec 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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() of a module in its top-level await resolves early when the module is a static dependency of another dynamic import

2 participants