workers-sdk
workers-sdk copied to clipboard
Dispatch Namespace Binding Missing in Durable Object `env` During `wrangler dev` Simulation When Other DO Bindings Exist
Which Cloudflare product(s) does this pertain to?
Wrangler
What versions & operating system are you using?
wrangler 4.13.1, node v23.7.0, sequoia 15.4.1 (24E263)
Please provide a link to a minimal reproduction
No response
Describe the Bug
Hey!
I'm running into an issue with wrangler dev where Dispatch Namespace bindings defined in my wrangler.toml aren't showing up in the env object passed to my Durable Object constructors during local simulation.
My Setup:
-
A main Worker (
src/index.ts). -
Two Durable Object classes:
DO_A(src/durable-objects/do_a.ts) andDO_B(src/durable-objects/do_b.ts). -
Another Worker service (
user-worker) which is the target for a Dispatch Namespace. -
My
wrangler.tomllooks something like this:name = "binding-test" main = "src/index.ts" compatibility_date = "2024-04-05" [[durable_objects.bindings]] name = "DO_A" class_name = "DO_A" [[durable_objects.bindings]] name = "DO_B" class_name = "DO_B" [[dispatch_namespaces]] binding = "DISPATCH_NS" namespace = "user-worker" # Name of the target worker service
Expected Behavior:
When I run wrangler dev and an instance of DO_A gets created, I expect the env object passed to its constructor to contain all the bindings defined globally in wrangler.toml – specifically DO_A, DO_B, and DISPATCH_NS. I should then be able to access this.env.DISPATCH_NS from within my DO_A instance (e.g., in its Workspace or alarm methods).
Actual Behavior:
- When I log
Object.keys(env)inside theDO_Aconstructor, it only shows the keys for the Durable Object bindings:DO_A, DO_B.// In DO_A constructor constructor(state: DurableObjectState, env: Env) { this.env = env; // This only logs "DO_A, DO_B" console.log(`DO_A Constructor: Received env keys:`, Object.keys(env).join(', ')); // ... } - The key for the Dispatch Namespace binding (
DISPATCH_NS) is missing from theenvobject. - Consequently, any code inside
DO_Athat tries to accessthis.env.DISPATCH_NS(likethis.env.DISPATCH_NS.fetch(...)) fails locally with an error like "TypeError: Cannot read properties of undefined (reading 'fetch')". - I've double-checked my
wrangler.tomlsyntax and it seems correct. - I also tried commenting out the
DO_Bbinding, andDISPATCH_NSwas still missing from theenvpassed toDO_A(the keys were justDO_A).
Impact:
This prevents me from testing any Durable Object logic locally that needs to interact with another Worker via a Dispatch Namespace. My code works correctly when deployed, but the local development workflow is broken for this use case.
Steps to Reproduce:
- Create a project with a main Worker, two DO classes (
DO_A,DO_B), and a separate target Worker (user-worker). - Configure
wrangler.tomlas shown above, bindingDO_A,DO_B, andDISPATCH_NS(pointing touser-worker). - In the
DO_Aconstructor, logObject.keys(env). - In some method of
DO_A(likeWorkspaceoralarm), try to callthis.env.DISPATCH_NS.fetch(...). - Run
wrangler dev. - Trigger an action that instantiates
DO_Aand calls the method from step 4. - Observe that the constructor log is missing
DISPATCH_NSand the attempt to accessthis.env.DISPATCH_NSthrows an error.
( yeah I used LLM to rewrite the description but I promisse that I wrote most of it 😅 )
Error logs
✘ [ERROR] A_DO 22e3021f-4fd8-41d7-bba5-a41ad65273fe: DISPATCH_NS binding missing! Cannot trigger worker.
I thought for a second that deploying to cloudflare fixed the issue, but this is happening in production as well.
Hiya, so this is expected in dev, where dispatch namespaces are not supported. I did try and reproduce this in production though, and i do seem to be getting the dispatch namespace binding when i deploy. Would you be able to provide a link to a repo with a minimal reproduction so we can test and help debug?
We haven't heard from you in while so I'm going to close this issue for now. If you're still running into problems feel free to open a new issue with more details and we can investigate further.