Home > Enterprise >  Can I run and debug deno project in VSCode?
Can I run and debug deno project in VSCode?

Time:05-12

I'm new to both typescript and deno, also vscode.

Firstly, I tried it with vscode and failed, and then tried with IntelliJ. I can run and debug simple .ts file in Intellij with deno plugin.

But I want to know how to do this in vscode(also installed deno plugin, enter image description here

CodePudding user response:

Debugging with --inspect does not work for relatively short programs, because it does not wait for the debugger to connect. So when running short programs the execution finishes before VS Code connects to the inspector. On larger programs this won't be an issue.

For debugging Deno programs that are only a couple of lines long, two options are given in this thread:

  • Use --inspect-brk instead of --inspect, this should allow enough time for the debugger to connect and hit breakpoints
  • Add some time delay to the code when debugging, for example:
const _sleep = async () => {
  await new Promise(resolve => setTimeout(resolve, 2000));
}
await _sleep();

console.log("Hello World!"); <-- Here, you could add a breakpoint

To Run without Debugging, you can also either add --inspect-brk, but you will have to press F5 or click 'Continue' once the session has started. Or, you can use --inspect and add the sleep function

  • Related