-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Synchronous exceptions in ES modules are always 'caught' #50430
Comments
Related on Stack Overflow: Why doesn't the VS Code JS Debugger pause on uncaught exceptions in ES modules in NodeJS?. Is this problem limited to NodeJS v20? Or does it go back to older versions as well? |
@nodejs/loaders |
The initial version of #50096 involved updating I’m not sure that would actually fix the issue, though. In particular, why isn’t the debugger breaking on the line where the exception is re-thrown: node/lib/internal/modules/esm/module_job.js Line 241 in 0a0b8df
Is it because it’s in the ignorelist? |
I faced the same problem in node+ts project. I solved it by set "target": "ES6", tsconfig.json. (at least in debugging config). There is few restrictions (as no root await) raised, But for me it is less problematic. |
Is there any update on this? But when I try to debug an esm script with vs code debugger it still doesn't pause on errors.
And it's just a pain. |
There are similar problems in other places too. As example some time ago preact had no try catch wrappers in event handlers and it was easy to debug your app. But later they added try catch blocks and development some time become to hell. I think problems like that should be handled as it was in flash. Debug player for development , where all errors crash as early as possible, and release player for productoin where errors handling are enabled. |
This also affects rejections from top-level await in ES modules and continues to reproduce on Node 22.7.0. |
This has cost me a lot of wasted time as well. A workaround seems to be to run your top-level code inside |
All module evaluations are asynchronous even if they could be evaluated synchronously. There are shortcuts in This is rather a V8/inspector issue that V8 inspector only supports This can also be reproduced in Chrome where a uncaught module top level exception can not be paused in the Chrome DevTools. <!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"></head>
<body></body>
<script type="module">
// This does not pause even with "Pause on uncaught exception" in Chrome DevTools
throw new Error('foobar');
</script>
</html> If V8 supports Upstream issue: https://issues.chromium.org/issues/397130621 |
Version
20.3.1
Platform
Darwin mbp.peet.io 22.6.0 Darwin Kernel Version 22.6.0: Fri Sep 15 13:39:52 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_X86_64 x86_64
Subsystem
inspector
What steps will reproduce the bug?
throw new Error('foo');
in an ES moduleHow often does it reproduce? Is there a required condition?
100%
What is the expected behavior? Why is that the expected behavior?
The runtime should pause on the
throw
lineWhat do you see instead?
The runtime does not pause and the program exits
Additional information
First reported in microsoft/vscode-js-debug#1861
Guessing this is because module evaluation is in a try/catch. Wonder if there's any machinery that can be used to mark containing exceptions as uncaught
node/lib/internal/modules/esm/module_job.js
Lines 217 to 219 in 0a0b8df
The text was updated successfully, but these errors were encountered: