Attach VSCode Debugger while running more than one worker with wrangler dev
I have more than one worker in my project and wish to debug them locally during development using VSCode. The CloudFlare docs recommend running multiple workers with a single command like this:
yarn wrangler dev -c ./app/wrangler.jsonc -c ./api/wrangler.jsonc
(docs: https://developers.cloudflare.com/workers/development-testing/multi-workers/#single-dev-command)
However, when doing this I cannot deterministically attach the debugger to any specific service. It seems wrangler decides which service loads first (presumably based on the dependency tree between them as specified in the wrangler.jsonc services bindings?) and then only the first worker binds the inspector to port 9229. I've tried rearranging the order of wrangler parameters to influence this to no avail. I also tried adding inspector_port
in the wrangler.jsonc but it seems that option is not supported?
Is there any way to run multiple workers via wrangler dev
and attach a debugger to either all of them, or choose which worker gets the 9229 debugger port, or assign unique debugger ports to each worker being run?Cloudflare Docs
Developing with multiple Workers
Learn how to develop with multiple Workers using different approaches and configurations.
2 Replies
inspector-port cli arg
Thanks @James. I made another attempt using concurrently to run wrangler dev separately multiple times each time passing in a parameter for --inspector-port so the 3 projects get 9229, 9230, 9231 for inspector port. This works. It's just messy to spread configuration in multiple locations with wrangler.jsonc & package.json relying on eachother. Ideally cloudflare would support
inspect_port
option in the wrangler.jsonc
as they do most other CLI dev options.