Visual Studio Code Wrangler Debug Configuration #4174
JustinGrote
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
|
Hi @JustinGrote, do you know how to debug Wrangler on Visual Studio 2022? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
You can use this to attach and debug Cloudflare Workers written in Typescript using the new
workerdlocal process that ships in Wrangler v3. Put it in yourlaunch.jsonfile for the project or your settings.jsonlaunchsetting.Warning
Until #4127 lands, you must have your repository on the C: drive on windows for this to work, otherwise it will silently fail if you have it on for instance D: when using DevDrive.
Task and Attach Method (Recommended)
Launch Method
{ "configurations": [ { "name": "Wrangler Dev", "type": "node", "request": "launch", "resolveSourceMapLocations": ["**", "!**/node_modules/**"], //This is key, the source maps to resolve end up located in your temp directory, and vscode by default only looks in your workspace directory. You can also set this to null or an empty array, but source maps in node_modules might get evaluated which may slow you down significantly unless you specifically want to debug those. "program": "${workspaceFolder}/node_modules/wrangler/bin/wrangler.js", // You can also use the CLI directly but this is cleaner. Alternatively, you can define your start in tasks.json and make this depend on it via preLaunchTask, as long as whatever port you start the inspector on matches the port defined here for attachSimplePort "args": ["dev", "--inspector-port=59229"], //Force a high port to avoid conflicts with other debuggers "attachSimplePort": 59229, //Matches --inspector-port above "internalConsoleOptions": "neverOpen", // We want to see Wrangler's output usually so hide this "console": "integratedTerminal", // Shows the wrangler output "autoAttachChildProcesses": false }, { "name": "Attach to existing Wrangler", "type": "node", "request": "attach", "resolveSourceMapLocations": ["**", "!**/node_modules/**"] } ] }Now when you visit a site, you should be able to hit typescript breakpoints set in your files:

Test Debugging
For Wrangler v3, while you can use
miniflare, its lack of step-through debugging is a real pain when troubleshooting. Instead, I recommend using theTask and Attach Methodabove to get your wrangler dev going and attached, and then adding something like this to your tests:Basically, if you have your
wrangler devrunning, your tests will use that, and step through debugging will work as long as you have it running. If you don't, it will spin up a temporaryworkerdfor that purpose.You can also use
miniflare v3, which usesworkerdon the backend, if you need to test some more advanced or nuanced scenarios, however this does not have step-through debugging and does not have native typescript support (you'll have to bundle/compile yourself rather than use wranglerd)https://github.com/cloudflare/miniflare/blob/v3.20231002.1/packages/miniflare/README.md
Beta Was this translation helpful? Give feedback.
All reactions