Debugging
This guide explains how to set up VS Code or Cursor to debug both your client-side and server-side (worker) code.
For debugging to work, you’ll need a .vscode/launch.json file in your project. If you created your project with create-rwsdk, this file should already be there.
If not, create the file and add the following configuration:
{ "version": "0.2.0", "configurations": [ { "name": "Debug Vite App (Client)", "type": "chrome", "request": "launch", "url": "http://localhost:5173", "webRoot": "${workspaceFolder}", "sourceMaps": true, "skipFiles": ["<node_internals>/**"] }, { "name": "Attach to Worker", "type": "node", "request": "attach", "port": 9229, "address": "localhost", "restart": false, "protocol": "inspector", "skipFiles": ["<node_internals>/**"], "localRoot": "${workspaceFolder}", "remoteRoot": "${workspaceFolder}", "sourceMaps": true }, { "name": "Attach to Worker (Port 9299)", "type": "node", "request": "attach", "port": 9299, "address": "localhost", "restart": false, "protocol": "inspector", "skipFiles": ["<node_internals>/**"], "localRoot": "${workspaceFolder}", "remoteRoot": "${workspaceFolder}", "sourceMaps": true } ]}Debugging Server-Side Code (Worker)
Section titled “Debugging Server-Side Code (Worker)”To debug server-side code, such as server components or server functions:
-
Start the dev server in your terminal:
Terminal window npm run dev -
Attach the debugger:
- In VS Code, open the “Run and Debug” panel (Cmd+Shift+D on Mac, Ctrl+Shift+D on Windows).
- Select “Attach to Worker” from the dropdown and press the play button (F5).
- If the terminal shows a message like “Default inspector port 9229 not available, using 9299 instead,” use the “Attach to Worker (Port 9299)” configuration instead.
-
Set breakpoints: Place breakpoints in your server-side code (e.g., in
src/worker.tsxor a server component). They should now be hit when the code is executed.
Debugging Client-Side Code
Section titled “Debugging Client-Side Code”- Make sure your dev server is already running.
- In the “Run and Debug” panel, select “Debug Vite App (Client)” and press F5.
- This will open a new Chrome window. Breakpoints in your client-side code (e.g., components with a
"use client"directive) will now work.
Limitations
Section titled “Limitations”Currently, debugging server-side rendering (SSR) of components is not fully supported. However, you can debug other worker code paths, including server components and server functions, as well as all client-side code.