Running workerd with verbose logging
Enable verbose output to see detailed logs:Watch mode for development
Automatically reload when config or code changes:Debugging in Visual Studio Code
Prerequisites
Install extensions
Install recommended extensions:
- LLVM clangd - Code completion
- Microsoft C/C++ - Debugging
Debug configurations
workerd includes several debug configurations in.vscode/launch.json:
| Configuration | Description |
|---|---|
| workerd (dbg) | Debug workerd server with a config file |
| workerd with inspector enabled (dbg) | Debug with V8 inspector enabled |
| workerd test case (dbg) | Debug a C++ test binary |
| workerd wd-test case (dbg) | Debug a .wd-test file |
Debugging the server
Select configuration
Choose workerd (dbg) or workerd with inspector enabled (dbg) from the dropdown.
Launch debugger
Press
F5 to launch with the debugger attached.You’ll be prompted for a config file. Default: samples/helloworld/config.capnpDebugging tests
Debug a C++ test
- Select workerd test case (dbg)
- Press
F5 - Enter the test binary path (default:
bazel-bin/src/workerd/jsg/jsg-test)
Debug a .wd-test
- Select workerd wd-test case (dbg)
- Press
F5 - Enter the test file path (default:
src/workerd/api/node/path-test.wd-test)
Using LLDB with WPT tests
Debug Web Platform Tests with LLDB:Using the V8 Inspector
When you run workerd with inspector enabled, you can connect Chrome DevTools:Start with inspector
Launch workerd with inspector enabled (VSCode: workerd with inspector enabled (dbg)).
Connect DevTools
Open Chrome/Edge and navigate to:Your workerd instance should appear under Remote Target.
Clangd for code navigation
Set up clangd for better code completion and navigation:Generate compile commands
compile_commands.json for project-wide operations like “Find References”.The
compile_flags.txt file provides basic compiler arguments. If it’s not working, check docs/vscode.md for troubleshooting steps.Common debugging scenarios
Debugging a Worker script
Create a test config file:config.capnp
Debugging memory issues
Run tests with AddressSanitizer:Debugging compilation errors
Stream test output to see full error messages:Finding the source of a crash
Use the debug build with symbols:Debugging tips
Enable source maps for TypeScript
Enable source maps for TypeScript
When debugging TypeScript workers, ensure your build process generates source maps. workerd will use them for better stack traces.
Check compatibility dates
Check compatibility dates
Many issues are resolved by using the correct compatibility date. See the compatibility dates documentation for details.
Use the samples directory
Use the samples directory
The
samples/ directory contains working examples you can use as debugging references:Stream test output
Stream test output
Use
just stream-test instead of just test to see real-time output, which is helpful for debugging test failures.Development container
workerd includes a devcontainer setup for consistent development environments:- Install the Dev Containers extension
- Use Dev Containers: Open Folder In Container in VSCode
- The container includes all dependencies pre-configured
Next steps
Testing
Learn to write and run tests
Wrangler integration
Use workerd with Wrangler