Enabling the debugger
--inspect
Pass --inspect to start a WebSocket debug server alongside your script:
--inspect-brk
Identical to --inspect, but injects a breakpoint at the very first line of the script before any code executes. Useful for short-lived scripts that exit before you can attach a debugger:
--inspect-wait
Identical to --inspect, but Bun waits for a debugger to attach before executing any code. Useful when you need to set breakpoints before the process starts:
Setting a custom port or URL
All three flags accept an optional port number, hostname, or URL prefix:Connecting a debugger
debug.bun.sh
Bun hosts a web-based debugger at debug.bun.sh. It is a modified version of WebKit’s Web Inspector, familiar to Safari users.
Open the URL printed by --inspect in your browser to start a session. The interface provides:
- Sources tab — View source code, set breakpoints, and step through execution.
- Console tab — Run arbitrary JavaScript in the context of your running program.
- Scope inspector — Examine local variables and their properties at any breakpoint.
Open the debug URL in your browser
Copy the
https://debug.bun.sh/#... URL from the terminal and open it.Trigger the code path
Send a request or run the code that hits the breakpoint. Execution pauses and the debugger activates.
Execution controls
| Button | Description |
|---|---|
| Continue script execution | Resume running until the next breakpoint or exception. |
| Step over | Advance to the next line without entering function calls. |
| Step into | Enter the function call on the current line. |
| Step out | Finish executing the current function and return to the call site. |
VS Code debugger
Bun has experimental support for debugging in Visual Studio Code via the Bun VS Code extension. After installing the extension, add a launch configuration to.vscode/launch.json:
"launch" configuration to start and debug a script directly from VS Code, or use "attach" to connect to a process already running with --inspect.
Debugging network requests
Set theBUN_CONFIG_VERBOSE_FETCH environment variable to log all fetch() and node:http requests automatically.
| Value | Description |
|---|---|
curl | Print each request as a curl command. |
true | Print request and response headers. |
false | No output. Default. |
Log as curl commands
> are the outgoing request; lines with < are the response.
Log request and response headers
Sourcemaps and stack traces
Bun transpiles every file it runs, but automatically generates sourcemaps so that stack traces point to your original TypeScript or JSX source — not the transpiled output. Sourcemaps are generated both for on-demand transpilation and forbun build output.
Source preview on errors
When an unhandled exception occurs, Bun prints a syntax-highlighted source preview showing where the error originated:Bun.inspect:
V8 stack trace compatibility
Bun uses JavaScriptCore, but formatserror.stack to match Node.js’s V8 output. This ensures compatibility with libraries that expect V8-style stack traces.
Bun also implements the V8 Stack Trace API, including Error.prepareStackTrace and Error.captureStackTrace:
Error.captureStackTrace lets you adjust where a stack trace begins, which is useful in callback-heavy or async code: