Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug JavaScript / Typescript in VSCode using Bun.sh

I have recently started playing with Bun to run typescript files without compiling them to js. So far so good. Eventually I wanted to debug at runtime but couldn't find anything about it in the docs.

How can I configure my .vscode/launch.json file to debug a project using bun?

I tried playing around with a configuration but didn't get very far:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Bun",
            "type": "node",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "runtimeExecutable": "bun",
            "runtimeArgs": ["run"]
        }
    ]
}

Looking through the official roadmap, I see nothing about debugging, but maybe it is an experimental feature at this point?

like image 888
Felipe Avatar asked Apr 28 '26 17:04

Felipe


1 Answers

It is possible now. Install the 1st party extension.

The extension explainer shows suggests a launch.json and settings.json to enable the command "Bun: Run File".

For me I had my bun installed as a devDependancy, and out-of-the-box the extension could not find the runtime, so I modified the settings.json as follows:

{
    // The path to the `bun` executable.
    "bun.runtime": "node_modules/bun/bin/bun",
    // If support for Bun should be added to the default "JavaScript Debug Terminal".
    "bun.debugTerminal.enabled": true,
    // If the debugger should stop on the first line of the program.
    "bun.debugTerminal.stopOnEntry": false,
}

With that in place run "Bun: Run File" would work with the the debugger

like image 172
Tom Larkworthy Avatar answered May 01 '26 07:05

Tom Larkworthy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!