esm: add import trace for evaluation errors#61612
Open
mattskel wants to merge 1 commit intonodejs:mainfrom
Open
esm: add import trace for evaluation errors#61612mattskel wants to merge 1 commit intonodejs:mainfrom
mattskel wants to merge 1 commit intonodejs:mainfrom
Conversation
Errors thrown during ESM module evaluation often do not show how the failing module was reached via imports, making it hard to understand why it was loaded. This change appends an "Import trace" section to the formatted error stack for evaluation-time ESM errors. The trace is derived from the loader’s import graph and shows the chain of modules leading to the failure. The implementation preserves existing stack formatting and source map handling, and is limited to module evaluation only. A new test verifies that the expected import chain is included. Refs: nodejs#46992
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61612 +/- ##
==========================================
- Coverage 89.76% 89.75% -0.02%
==========================================
Files 673 673
Lines 203944 204013 +69
Branches 39191 39208 +17
==========================================
+ Hits 183080 183104 +24
- Misses 13194 13238 +44
- Partials 7670 7671 +1
🚀 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 PR adds an import trace to error output for errors thrown during ESM module evaluation. The trace shows the chain of modules that led to the failing module, making it easier to understand why a module was loaded.
When an error is thrown during ESM evaluation, the resulting stack trace often lacks information about the importer chain. This makes debugging difficult, especially in cases where a module is imported indirectly.
This change addresses that gap by appending a clearly separated “Import trace” section to the formatted error stack.
Adds a new ESM test covering evaluation-time import failures
Fixes: #46992