module: show user location for missing module errors, resolve #38892#62885
Open
meixg wants to merge 1 commit intonodejs:mainfrom
Open
module: show user location for missing module errors, resolve #38892#62885meixg wants to merge 1 commit intonodejs:mainfrom
meixg wants to merge 1 commit intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
d24ea56 to
a9aeca0
Compare
a9aeca0 to
2142429
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #62885 +/- ##
==========================================
+ Coverage 89.62% 89.64% +0.01%
==========================================
Files 706 706
Lines 219137 219492 +355
Branches 41981 42065 +84
==========================================
+ Hits 196404 196763 +359
- Misses 14614 14617 +3
+ Partials 8119 8112 -7
🚀 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.
Fixes: #38892
Summary
This improves the source location shown for uncaught missing module errors.
Previously, some missing module failures displayed an internal loader location at the top of the fatal exception output, such as
node:internal/modules/..., instead of pointing at the userimport, dynamicimport(), orrequire()expression that triggered the resolution failure.
This change decorates missing module errors with an arrow message that points to the user source location.
Covered cases:
importimport()require()Implementation
For static ESM imports,
ModuleWrap#getModuleRequests()now exposes the line and column for each module request. The ESM linking path uses that information when decoratingERR_MODULE_NOT_FOUND.For dynamic
import(), the loader temporarily increasesError.stackTraceLimitaround the synchronousgetOrCreateModuleJob()call so the originalERR_MODULE_NOT_FOUNDstack can retain the user import frame. The decorator then usesthat frame to locate the dynamic import expression.
For CommonJS,
MODULE_NOT_FOUNDdecoration uses the current structured stack to find the parent module call site, avoiding parsing the formattederr.stackstring.The source snippet formatting is centralized in
internal/errors/error_source.js, including clipping for long source lines.Example
Before:
After:
Tests
Added coverage for:
Relevant tests: