I have a simple path/to/test.ts script:
console.log(Deno.cwd())
It runs fine with deno run --allow-read .\test.ts and returns path/to as expected. However using the debugger it returns nothing before exiting.
Why is that? Here is the content of launch.json:
{
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Deno",
"type": "node",
"program": "${file}",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--allow-read"
],
"attachSimplePort": 9229
}
]
}
I try ${fileDirname}, ${workspaceFolder} and ${cwd} value for the cwd key but it doesn't help.
See more: Visual Studio Code Variables Reference
Also asked on GitHub
The debugger is a separate process with its own I/O streams (e.g. console).
When debugging a program, any data that's emitted to one of the program's I/O streams (e.g.
stdoutviaconsole.log) will not be forwarded to the debugger's console until after the debugger connects to the program and creates a pipe to that stream. That connection process takes time, and almost certainly won't happen until after the singleconsole.logstatement already finishes in the example program that you showed.Deno's
runcommand supports an argument to delay execution until after a debugger connects (added in denoland/deno#17001) — this argument is--inspect-wait.From the manual:
Include it in the array of args in
configurations.runtimeArgsin./.vscode/launch.json:After adding that argument, I can run your example reproduction files in a VS Code workspace using the debugger and I see this in the debugger console:
Here are the software versions I used to reproduce the issue:
Edit: It looks like a Deno core team member just responded at your GitHub issue with a summarized version of the same info.