Commit 71ff996
committed
module: fix wrong error annotation for require of ESM
When a CommonJS module requires an ES module with
--no-experimental-require-module, the error annotation (arrow message)
was pointing to an internal frame (TracingChannel.traceSync in
node:diagnostics_channel) instead of the user's actual require() call.
This happened because reconstructErrorStack() was always picking the
first 'at' frame from the error stack trace. When the require() call
is wrapped by TracingChannel.traceSync (added in v22.4.0 via
wrapModuleLoad), the first frame is the internal tracing wrapper, not
the user's code.
Fix reconstructErrorStack() to search the stack frames for one that
matches the parent module's file path, instead of blindly using the
first frame. This ensures the error annotation correctly points to the
user's require() call.
Also remove a TODO comment that this change addresses.
Fixes: #553501 parent 9f0a3e6 commit 71ff996
File tree
2 files changed
+125
-57
lines changed- lib/internal/modules/cjs
- test/es-module
2 files changed
+125
-57
lines changed
0 commit comments