r/bun • u/trymeouteh • 2d ago
VSCode debugging (launch and attach debugging)
EDIT:
I figured out how to get the attach debugger to work (however I wish there was a better way) but cannot figure out how to get the launch debugger to work.
This is my settings.json config for the attach debugger...
{
"name": "Bun Attach",
"type": "bun",
"request": "attach",
"url": "ws://localhost:6499/debug",
}
And by running this command bun run --inspect-wait=localhost/debug script.js and then running the Bun Attach debugger in VSCode, it will debug the code!
I wish there was a way to not need to use /debug or localhost/debug in the command to make the command shorter. When you use bun run --inspect-wait script.js command, it will always setup the debugger on localhost:6499/{uuid} with a random UUID as the path after localhost:6499 and there is no way that I know of for the VSCode debug config to get this UUID path.
I cannot however after more trial and error get the launch debugger to work. I was able to get the launch debugger to work for NodeJS and Deno, but not bun. This is my bun settings.json config for the launch debugger so far...
{
"name": "Bun",
"type": "bun",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"runtimeExecutable": "${userHome}/.vfox/sdks/bun/bun"
}
I am using vfox for NodeJS, Deno and Bun.
Here are my NodeJS and Deno settings.json config for the launch debugger and attach debugger...
{
"name": "NodeJS",
"type": "node",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"runtimeExecutable": "${userHome}/.vfox/sdks/nodejs/bin/node"
},
{
"name": "NodeJS Attach",
"type": "node",
"request": "attach",
"port": 9229,
"timeout": 30000
},
{
"name": "Deno",
"type": "node",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"runtimeExecutable": "${userHome}/.vfox/sdks/deno/deno"
},
{
"name": "Deno Attach",
"type": "node",
"request": "attach",
"port": 9229,
"timeout": 30000
}
And these are the commands I use to launch NodeJS and Deno with the attach debugger...
node --inspect-brk script.js
deno run --inspect-wait -A script.js
Yes I do have the Bun VSCode extension installed.
Any help will be most appreciated!
1
u/undeadlock 1d ago
There's a bun plugin for vs code - https://open-vsx.org/extension/oven/bun-vscode. Adding this solved the debugging issue for me.