[v24.x] backport ERR_REQUIRE_ASYNC_MODULE improvements - #65125
Open
joyeecheung wants to merge 2 commits into
Open
[v24.x] backport ERR_REQUIRE_ASYNC_MODULE improvements#65125joyeecheung wants to merge 2 commits into
joyeecheung wants to merge 2 commits into
Conversation
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> PR-URL: nodejs#64154 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This brings back several improvements that were reverted by mistake when landing https://redirect.github.com/nodejs/node/pull/64154 - Update the documentation about how the removal of side effects of source collection - Add non-enumerable `requireStack` and `topLevelAwaitLocations` properties to `ERR_REQUIRE_ASYNC_MODULE`, the latter is only populated when --experimental-print-required-tla is enabled - Add "Required module: <url>" to the error message to identify the required ESM entry point regardless of whether the flag is enabled - Fix TLA caret column from 0-based to 1-based - Store module source via a private symbol instead of a public property - Use `hasAsyncGraph` (post-instantiation) in `throwIfAsyncGraph` instead of walking the graph before instantiation - Merge the require stack checking into the `common.expectRequiredTLAError` helper. - Removed tests that are made redundant by the snapshot tests Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com> PR-URL: nodejs#64260 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Collaborator
|
Review requested:
|
aduh95
reviewed
Aug 7, 2026
| description: Added the `requireStack` and `topLevelAwaitLocations` properties. | ||
| --> | ||
|
|
||
| When trying to `require()` a [ES Module][], the module turns out to be asynchronous. |
Contributor
There was a problem hiding this comment.
Suggested change
| When trying to `require()` a [ES Module][], the module turns out to be asynchronous. | |
| When trying to `require()` an [ES Module][], the module turns out to be asynchronous. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v24.x-staging #65125 +/- ##
=================================================
+ Coverage 89.92% 90.31% +0.39%
=================================================
Files 686 711 +25
Lines 208389 228424 +20035
Branches 40077 43158 +3081
=================================================
+ Hits 187387 206310 +18923
- Misses 13238 14080 +842
- Partials 7764 8034 +270
🚀 New features to boost your workflow:
|
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.
This backports #64260 and #64154