fix(core): evaluate pre-instantiated module in lazy_load_esm_module#33973
Merged
Conversation
When a lazy-loaded ESM module is already registered in the module map (e.g. as a static import in the user's bundle that V8 instantiated during the link phase), the early-return path handed back the namespace without checking the module's evaluation status. If V8 hadn't reached that module yet in its DFS post-order evaluation, the namespace's `export const` bindings were in the temporal dead zone — surfacing as `Cannot access 'X' before initialization` from any caller that destructures the lazy namespace at module evaluation time. Surfaced through gemini-cli: events_esm.ts destructures `EventEmitterAsyncResource`, whose lazy getter loads node:async_hooks, which is a sibling static import elsewhere in the bundle. Fixes #33940
nathanwhit
approved these changes
May 11, 2026
littledivy
pushed a commit
to crowlKats/deno
that referenced
this pull request
Jun 10, 2026
…enoland#33973) The early-return path of `lazy_load_esm_module` handed back a module's namespace without checking the module's evaluation status. When the module was already registered in the module map (e.g. as a static import in the caller's bundle that V8 instantiated during the link phase) but V8 hadn't reached it yet in DFS post-order, the namespace's `export const` bindings were in the temporal dead zone — so any caller that destructured the lazy namespace at module evaluation time saw `Cannot access 'X' before initialization`. The fix evaluates the module before returning the namespace when its status is `Instantiated`, mirroring the existing logic in `lazy_load_es_module_with_code`. The user-visible symptom was gemini-cli failing at startup with `Cannot access 'AsyncResource' before initialization`. The recent events_esm.ts wrapper destructures `EventEmitterAsyncResource`, whose lazy getter loads `node:async_hooks` — itself a sibling static import elsewhere in the bundle, so it had been instantiated but not yet evaluated. Fixes denoland#33940
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The early-return path of
lazy_load_esm_modulehanded back a module'snamespace without checking the module's evaluation status. When the
module was already registered in the module map (e.g. as a static
import in the caller's bundle that V8 instantiated during the link
phase) but V8 hadn't reached it yet in DFS post-order, the namespace's
export constbindings were in the temporal dead zone — so any callerthat destructured the lazy namespace at module evaluation time saw
Cannot access 'X' before initialization. The fix evaluates themodule before returning the namespace when its status is
Instantiated, mirroring the existing logic inlazy_load_es_module_with_code.The user-visible symptom was gemini-cli failing at startup with
Cannot access 'AsyncResource' before initialization. The recentevents_esm.ts wrapper destructures
EventEmitterAsyncResource, whoselazy getter loads
node:async_hooks— itself a sibling static importelsewhere in the bundle, so it had been instantiated but not yet
evaluated.
Fixes #33940