-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module: fix error reporting #55561
base: main
Are you sure you want to change the base?
module: fix error reporting #55561
Conversation
Review requested:
|
24a4e77
to
35c501d
Compare
35c501d
to
07e16a1
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #55561 +/- ##
=======================================
Coverage 88.42% 88.42%
=======================================
Files 654 654
Lines 187662 187698 +36
Branches 36118 36123 +5
=======================================
+ Hits 165945 165978 +33
- Misses 14955 14961 +6
+ Partials 6762 6759 -3
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening a PR! Can you please add a unit test?
dc12f2a
to
dc88885
Compare
Sure! It's done 🫡 |
dc88885
to
95bc2ce
Compare
ded0ecb
to
7dc8b15
Compare
I think this isn't what the error reporting should do? Let me investigate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See:
function main() {
func1(func2(func3()))
}
function func1() {
require('./app.js')
}
function func2() {}
function func3() {}
main()
Correct output:
➜ undefined git:(55350-issue) ✗ node -v
v22.3.0
➜ undefined git:(55350-issue) ✗ node test.cjs
/Users/rafaelgss/repos/os/node2/undefined/test.cjs:6
require('./app.js')
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/rafaelgss/repos/os/node2/undefined/app.js from /Users/rafaelgss/repos/os/node2/undefined/test.cjs not supported.
Instead change the require of app.js in /Users/rafaelgss/repos/os/node2/undefined/test.cjs to a dynamic import() which is available in all CommonJS modules.
at func1 (/Users/rafaelgss/repos/os/node2/undefined/test.cjs:6:3)
at main (/Users/rafaelgss/repos/os/node2/undefined/test.cjs:2:3)
at Object.<anonymous> (/Users/rafaelgss/repos/os/node2/undefined/test.cjs:11:1) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v22.3.0
After #44340:
➜ undefined git:(55350-issue) ✗ node test.cjs
/Users/rafaelgss/repos/os/node2/undefined/test.cjs:315
undefined
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/rafaelgss/repos/os/node2/undefined/app.js from /Users/rafaelgss/repos/os/node2/undefined/test.cjs not supported.
Instead change the require of app.js in /Users/rafaelgss/repos/os/node2/undefined/test.cjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at func1 (/Users/rafaelgss/repos/os/node2/undefined/test.cjs:6:3)
at main (/Users/rafaelgss/repos/os/node2/undefined/test.cjs:2:3)
at Object.<anonymous> (/Users/rafaelgss/repos/os/node2/undefined/test.cjs:11:1) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v22.4.0
Your PR:
➜ undefined git:(55350-issue) ✗ ../node --no-experimental-require-module test.cjs
/Users/rafaelgss/repos/os/node2/undefined/test.cjs:11
main()
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/rafaelgss/repos/os/node2/undefined/app.js from /Users/rafaelgss/repos/os/node2/undefined/test.cjs not supported.
Instead change the require of app.js in /Users/rafaelgss/repos/os/node2/undefined/test.cjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at func1 (/Users/rafaelgss/repos/os/node2/undefined/test.cjs:6:3)
at main (/Users/rafaelgss/repos/os/node2/undefined/test.cjs:2:3)
at Object.<anonymous> (/Users/rafaelgss/repos/os/node2/undefined/test.cjs:11:1) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v24.0.0-pre
I apologize; I haven’t had the bandwidth to look into how the fix should be structured yet. However, this change appears to be inaccurate
Wrong assumption from my side. Thanks for pointing that out. I just pushed a fix. It takes the first frame after TraseSync. I will also get this case you brought into a test. |
2e9d67e
to
9847e2d
Compare
9847e2d
to
00dfc8f
Compare
Can you try to use |
Would you guide me how I can do that? I tried to add it in a few places:
None worked. It ended up messing with the stack.
It adds this |
Refs: #55350
Fixes: #55350
The error is incorrectly reported because the
traceSync
call is on the stack frame. The code that computes the message was getting the first frame expecting it to have the information needed. Something likeWith
traceSync
it's likeThis PR fixes this behavior by skipping the first frame - TracingChannel.traceSync.