Skip to main content
Bun implements the WebKit Inspector Protocol, which lets you attach an interactive debugger to any running Bun process. You can debug using the hosted web inspector at debug.bun.sh or directly in VS Code.

Enabling the debugger

--inspect

Pass --inspect to start a WebSocket debug server alongside your script:
Bun prints the connection URL:

--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.
1

Start your script with --inspect

2

Open the debug URL in your browser

Copy the https://debug.bun.sh/#... URL from the terminal and open it.
3

Set a breakpoint

Navigate to the Sources tab. Click a line number to set a breakpoint.
4

Trigger the code path

Send a request or run the code that hits the breakpoint. Execution pauses and the debugger activates.
5

Inspect and step

Use the control buttons to continue, step over, step into, or step out of functions.

Execution controls

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:
Use the "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 the BUN_CONFIG_VERBOSE_FETCH environment variable to log all fetch() and node:http requests automatically.

Log as curl commands

Lines prefixed with > 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 for bun build output.

Source preview on errors

When an unhandled exception occurs, Bun prints a syntax-highlighted source preview showing where the error originated:
You can generate this preview manually using Bun.inspect:

V8 stack trace compatibility

Bun uses JavaScriptCore, but formats error.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: