It’s possible to debug Deno programs using Chrome Devtools or other clients that support the protocol (eg. VSCode).

    To activate debugging capabilities run Deno with the or --inspect-brk flags.

    The --inspect flag allows attaching the debugger at any point in time, while --inspect-brk will wait for the debugger to attach and will pause execution on the first line of code.

    Let’s try debugging a program using Chrome Devtools. For this, we’ll use from std, a static file server.

    Use the --inspect-brk flag to break execution on the first line:

    `

    `

    Open and click Inspect next to target:

    It might take a few seconds after opening the Devtools to load all modules.

    Devtools opened

    You might notice that Devtools paused execution on the first line of _constants.ts instead of file_server.ts. This is expected behavior and is caused by the way ES modules are evaluated by V8 (_constants.ts is left-most, bottom-most dependency of file_server.ts so it is evaluated first).

    Looking closely you’ll find duplicate entries for each file; one written regularly and one in italics. The former is compiled source file (so in the case of .ts files it will be emitted JavaScript source), while the latter is a source map for the file.

    Next, add a breakpoint in the listenAndServe method:

    Break in file_server.ts

    As soon as we’ve added the breakpoint Devtools automatically opened up the source map file, which allows us step through the actual source code that includes types.

    Now that we have our breakpoints set, we can resume the execution of our script so that we might inspect an incoming request. Hit the Resume script execution button to do so. You might even need to hit it twice!

    Once our script is running again, let’s send a request and inspect it in Devtools:

    `

    `

    At this point we can introspect the contents of the request and go step-by-step to debug the code.

    Deno can be debugged using VSCode.

    We can still attach the debugger by manually providing a launch.json config:

    `

    `

    NOTE: This uses the file you have open as the entry point; replace ${file} with a script name if you want a fixed entry point.

    Let’s try out debugging a local source file. Create server.ts:

    `

    `

    Then we can set a breakpoint, and run the created configuration:

    VSCode debugger

    You can debug Deno using your JetBrains IDE by right-clicking the file you want to debug and selecting the option. This will create a run/debug configuration with no permission flags set. To configure these flags edit the run/debug configuration and modify the Arguments field with the required flags.

    Any client that implements the Devtools protocol should be able to connect to a Deno process.

    Devtools support is still immature. There is some functionality that is known to be missing or buggy:

    • profiling and memory dumps might not work correctly.