Skip to content

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

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
joyeecheung:print-tla
Jul 2, 2026
Merged

module: print required top-level await without side effects#64154
nodejs-github-bot merged 2 commits 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
Comment thread lib/internal/modules/esm/module_job.js
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.

Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 29, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 29, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@joyeecheung

Copy link
Copy Markdown
Member Author

Fixed the line ending checks in tests for Windows. The CI seems happy. Can I get another review please? Thanks! @anonrig @aduh95

@joyeecheung joyeecheung added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 2, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 2, 2026
@nodejs-github-bot nodejs-github-bot merged commit 85c31df into nodejs:main Jul 2, 2026
64 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 85c31df

@joyeecheung joyeecheung added dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. dont-land-on-v24.x PRs that should not land on the v24.x-staging branch and should not be released in v24.x. dont-land-on-v26.x PRs that should not land on the v26.x-staging branch and should not be released in v26.x. labels Jul 2, 2026
@joyeecheung

Copy link
Copy Markdown
Member Author

I noticed that when trying to force push to fix the Windows issue, I was basing off an older version of the branch and therefore reverted some improvements I added later to the branch, e.g. the doc updates, making the properties non-enumerable, etc.

Since there's now another commit on the main branch and I think a fixup needs a re-run to confirm Windows is still clean, I opened #64260. Sorry about the mess-up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. dont-land-on-v24.x PRs that should not land on the v24.x-staging branch and should not be released in v24.x. dont-land-on-v26.x PRs that should not land on the v26.x-staging branch and should not be released in v26.x. 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.

4 participants