@@ -306,6 +306,38 @@ Default file:
|
306 | 306 | - Keep logs local and delete them after debugging. |
307 | 307 | - If you share logs, scrub secrets and PII first. |
308 | 308 | |
| 309 | +## Debugging in VSCode |
| 310 | + |
| 311 | +Source maps are required to enable debugging in VSCode-based IDEs because many of the generated files end up with hashed names as part of the build process. The included `launch.json` configurations target the Gateway service, but can be adapted quickly for other purposes: |
| 312 | + |
| 313 | +1. **Rebuild and Debug Gateway** - Debugs the Gateway service after creating a new build |
| 314 | +2. **Debug Gateway** - Debugs the Gateway service of a pre-existing build |
| 315 | + |
| 316 | +### Setup |
| 317 | + |
| 318 | +The default **Rebuild and Debug Gateway** configuration is batteries-included, it will automatically delete the `/dist` folder and rebuild the project with debugging enabled: |
| 319 | + |
| 320 | +1. Open the **Run and Debug** panel from the Activity Bar or press `Ctrl`+`Shift`+`D` |
| 321 | +2. In the IDE, ensure **Rebuild and Debug Gateway** is selected in the configuration dropdown and then press the **Start Debugging** button |
| 322 | + |
| 323 | +Alternatively - if you prefer to manage the build and debug processes manually: |
| 324 | + |
| 325 | +1. Open a terminal and enable source maps: |
| 326 | +- **Linux/macOS**: `export OUTPUT_SOURCE_MAPS=1` |
| 327 | +- **Windows (PowerShell)**: `$env:OUTPUT_SOURCE_MAPS="1"` |
| 328 | +- **Windows (CMD)**: `set OUTPUT_SOURCE_MAPS=1` |
| 329 | +2. In the same terminal, rebuild the project: `pnpm clean:dist && pnpm build` |
| 330 | +3. In the IDE, select the **Debug Gateway** option in the **Run and Debug** configuration dropdown and then press the **Start Debugging** button |
| 331 | + |
| 332 | +You can now set breakpoints in your TypeScript source files (`src/` directory) and the debugger will correctly map breakpoints to the compiled JavaScript via source maps. You'll be able to inspect variables, step through code, and examine call stacks as expected. |
| 333 | + |
| 334 | +### Notes |
| 335 | + |
| 336 | +- If using the **"Rebuild and Debug Gateway"** option - each time the debugger is launched it will completely delete the `/dist` folder and run a full `pnpm build` with source maps enabled before starting the Gateway |
| 337 | +- If using the **"Debug Gateway"** option - debug sessions can be started and stopped at any time without affecting the `/dist` folder, but you must use a separate terminal process to both enable debugging and manage the build cycle |
| 338 | +- Modify the `launch.json` settings for `args` to debug other sections of the project |
| 339 | +- If you need to use the built OpenClaw CLI for other tasks (i.e. `dashboard --no-open` if your debug session spawns a new auth token), you can execute it in another terminal as `node ./openclaw.mjs` or create a shell alias like `alias openclaw-build="node $(pwd)/openclaw.mjs"` |
| 340 | + |
309 | 341 | ## Related |
310 | 342 | |
311 | 343 | - [Troubleshooting](/help/troubleshooting) |
|