workers-sdk
workers-sdk copied to clipboard
🚀 Feature Request:RPC Support for Durable Objects in `wrangler dev`
Describe the solution
When binding a durable object using RPC that was defined in a different worker, it fails with:
Cannot access `MyDurableObject#myMethod` as Durable Object RPC is not yet supported between multiple `wrangler dev` sessions.
This is really useful when using durable objects in combination with wrangler pages dev since, as far as I understand, you cannot deploy a worker from a Pages project.
Can you try extending the DurableObject class in your code, which may resolve this problem. JS RPC entry points must derive from either DurableObject or WorkerEntrypoint.
Extending DurableObject does not fix this. The current behaviour as reported here is part of the test suite on current main, which indicates this would only be supported in the future: https://github.com/cloudflare/workers-sdk/pull/5215/commits/e469fb91a95b035642ca6b176c1f53bb15491081 / https://github.com/cloudflare/workers-sdk/blob/26855f39ae635feebb9d5768b64494e73d979b47/fixtures/entrypoints-rpc-tests/tests/entrypoints.spec.ts#L513-L593
OK thanks for the clarification. I wasn't sure if it had been fixed already. I'll add it to the backlog.
I can also confirm this... been struggling for over a week now, causing project delays because of this... And even if I deploy I'm unable to test this since I can't bind the DO to the Pages project (it's the only DO that doesn't appear in the bindings list, despite being deployed like all others).
Hey folks just chiming in with more support for this! I'm already using cross-worker RPC calls in dev, was surprised to see it didn't work on Durable Objects! Everything else is very lovely to work with, this would be the cherry on top!
Hey @alexturpin! Any updates or ETA for that feature?
@LilaRest sorry for the confusion, I'm not a Cloudflare employee, was just saying I would also find this very useful!
@alexturpin My bad, I'm quite tired and realize that I've sent the message in the wrong ticket mentioning the wrong person ^^ Thanks anyway for taking time to answer.
Any update guys ? this is bad DX :(
Currently, I have to deploy the worker (fast) and my next-on-pages project (slow) to test the even very small changes as long as the change has anything to do with the connection of these two and it slows the development process by an order of magnitude.
If this is going to be like this for a long time, I need to do something about it, so it would be nice if someone could provide an ETA.
A workaround would be also appreciated. If there is a hidden experimental implementation, etc., please let us know. Dealing with an unstable solution would be preferred than waiting 3-4 minutes to test a small iteration.
+1
OK thanks for the clarification. I wasn't sure if it had been fixed already. I'll add it to the backlog.
Hello! Could you share an update on this please? :) I just landed on this issue.
@gregory - see https://github.com/cloudflare/workers-sdk/pull/7098
A workaround is to use .fetch() on the durable object instead of rpc.
any news ?
any news ?
According to #7251 it was fixed (fix was merged) already... But I haven't tried it.
If you are not trying to communicate between Pages and Workers, #7251 should resolve this issue for you if you run all workers inside one wrangler dev session (if anyone finds any issues please let us know!).
Between Pages and Workers, we're looking into it but don't have any eta unfortunately :( A solution for Workers + Workers Assets will probably be incoming sooner as that is a simpler problem - worked on in #7290
as an workaround, you all can use this closed PR, it does not seem to work fetch tho , but hey RPC is working for me.
Am I confused, or should this not be closed?
I get this when running Wrangler v4.14.1 (latest as of writing):
✘ [ERROR] Error: Cannot access `StreamText#potato` as Durable Object RPC is not yet supported between multiple `wrangler dev` sessions.
```
When I run two separate wrangler dev processes, one hosting an HTTP API and one with a durable object, I get the error that started this git issue. However, when I run them together under a single wrangler dev process (ie. wrangler dev -c do/wrangler.jsonc -c api/wrangler.jsonc everything works great. I'm providing this note for anyone else finding this git issue.
Yes! I think this was the point of closing this issue. If you use the single process approach to multi-workers then this does indeed work.
@petebacondarwin is it possible to specify multiple configs with next-on-pages? I don't believe so from taking a look.
Since you can only connect to externally hosted Durable Objects from a Pages project there is no way to get this to work with next-on-pages. The only thing you could do is "fetch" out to a Worker from Pages and for that Worker to then bind to a Durable Object itself using the approach above.
That being said, we are encouraging people to consider moving away from Pages to Workers, and we have new OpenNext based Next.js tooling that lives on Workers rather than Pages. If you migrated to that, then you would get the benefits of the approach above.
I'm doing the fetch right now! I'll look at migrating, thank you :)
It should be possible to run wrangler pages dev with multiple configs, as long as the first config specified is the pages project. But like @petebacondarwin said, we'd recommend trying out Workers + OpenNext if that's something you're able to do :)
If you migrated to that, then you would get the benefits of the approach above.
@petebacondarwin can you kindly elaborate on this? initOpenNextCloudflareForDev takes a single optional config file, how can I run multiple workers in the same process?
OK thanks for the clarification. I wasn't sure if it had been fixed already. I'll add it to the backlog.
Hi @petebacondarwin, I was just wondering if this is still a planned fix/implementation? If not I'd like to request it be re-opened. I understand that the recommended way is to start all workers in a single instance, however, this is not ideal for large monorepos with multiple workers calling the same DO.
Furthermore, even if you do chain each wrangler.jsonc in one wrangler dev session you lose out on HMR if you have multiple frontends bound to the same DO. Thanks.
⚠️ You may see this error even with latest wrangler (4.46.0 at the moment) if you set script_name in the DO binding config. Even if you run a single wrangler dev instance. Remove the script_name to get rid of this:
Cannot access
MyDurableObject#myMethodas Durable Object RPC is not yet supported between multiplewrangler devsessions.
Took me a while to figure this out, error message does not give any clues at all. The only reason I even tried to remove the script_name was this paragraph from documentation:
wrangler dev has read access to Durable Object storage, but writes will be kept in memory and will not affect persistent data. However, if you specify the script_name explicitly in the Durable Object binding, then writes will affect persistent data. Wrangler will emit a warning in that case.