Why doesn't the VS Code JS Debugger pause on uncaught exceptions in ES modules in NodeJS?

176 views Asked by At

This recently became an issue and I'm not sure what triggered it. As soon as the debugger encounter's an error, it exits and prints:

Process exited with code 1

Which isn't very helpful at all.

I've got 'Uncaught Exceptions' checked under breakpoints.

Manually set breakpoints still work.

It doesn't matter if it errors in an async block, it doesn't pause in synchronously run blocks as well.

I've been getting by recently by using this code to help track down errors, but it's still pretty inconvenient:

process.on("uncaughtException", (e)=>{
  console.trace(e);
})

As far as I can tell this isn't an issue if the Javascript file is not a module (ie, package.json "type": "module")

Tried re-installing VS Code without any luck.

Any ideas?

1

There are 1 answers

0
starball On

The maintainer of the vscode-js-debug extension, Connor Peet, explained in the asker's issue ticket what the problem really is:

This is because the exception is actually caught by Node.js module loader, which can be seen if you step out in the call stack. Will open an issue on them.

The issue ticket they opened is Synchronous exceptions in ES modules are always 'caught' #50430. They found that NodeJS evaluates modules inside a try-catch block and wonder if there's a way to mark containing exceptions as uncaught. You can give that issue ticket a thumbs up to show support for it getting addressed, and subscribe to it to get notified about discussion and progress. Please avoid making noisy comments like "+1" / "bump".