Skip to content

module: print required top-level await without side effects#64154

Open
joyeecheung wants to merge 1 commit into
nodejs:mainfrom
joyeecheung:print-tla
Open

module: print required top-level await without side effects#64154
joyeecheung wants to merge 1 commit into
nodejs:mainfrom
joyeecheung:print-tla

Conversation

@joyeecheung

@joyeecheung joyeecheung commented Jun 26, 2026

Copy link
Copy Markdown
Member

This paves the way for enabling --experimental-print-required-tla by default.

Previously in order to collect the locations of the required TLA, we rely on v8::Module::GetStalledTopLevelAwaitMessages() which requires evaluating the module first, hence --experimental-print-required-tla incurred side-effects. This patch switches to parsing the graph using acorn to collect locations of TLAs instead when we need to throw ERR_REQUIRE_AYNSC_MODULE, so that we can print them without evaluating the modules and --experimental-print-required-tla is now free of side-effects.

In addition, we now collect and print the require stack for ERR_REQUIRE_ASYNC_MODULE too. It now carries two more non-enumerable properties:

  • requireStack: similar to the one carried by ERR_MODULE_NOT_FOUND
  • topLevelAwaitLocations: an array containing metadata about the located top-level-awaits in the graph.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/vm

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jun 26, 2026
Previously in order to collect the locations of the TLA, we wait
until right before evalutation to ensure instantiation is
completed so that we can use
v8::Module::GetStalledTopLevelAwaitMessages(). Now we try to
add an additioanl shortcut to the source code in the module wraps
instead during compilation for modules that contain TLAs and
use acron to locate the TLAs when we need to throw
ERR_REQUIRE_AYNSC_MODULE, so we can do this as early as before
instantiation and do not need to run the module again to collect
the locations.

In addition, we now collect the require stack for
ERR_REQUIRE_ASYNC_MODULE too for better metadata in the errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants