workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🚀 Feature Request:RPC Support for Durable Objects in `wrangler dev`

Open yawnt opened this issue 1 year ago • 10 comments

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.

yawnt avatar May 25 '24 17:05 yawnt

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.

petebacondarwin avatar Jun 24 '24 13:06 petebacondarwin

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

robbertvanginkel avatar Jun 24 '24 14:06 robbertvanginkel

OK thanks for the clarification. I wasn't sure if it had been fixed already. I'll add it to the backlog.

petebacondarwin avatar Jun 24 '24 15:06 petebacondarwin

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).

Chinoman10 avatar Jul 30 '24 22:07 Chinoman10

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!

alexturpin avatar Sep 08 '24 17:09 alexturpin

Hey @alexturpin! Any updates or ETA for that feature?

LilaRest avatar Oct 04 '24 19:10 LilaRest

@LilaRest sorry for the confusion, I'm not a Cloudflare employee, was just saying I would also find this very useful!

alexturpin avatar Oct 04 '24 20:10 alexturpin

@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.

LilaRest avatar Oct 04 '24 20:10 LilaRest

Any update guys ? this is bad DX :(

zhihengGet avatar Oct 14 '24 00:10 zhihengGet

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.

sassanh avatar Oct 18 '24 09:10 sassanh

+1

grokwich avatar Oct 25 '24 01:10 grokwich

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 avatar Oct 27 '24 11:10 gregory

@gregory - see https://github.com/cloudflare/workers-sdk/pull/7098

petebacondarwin avatar Oct 27 '24 14:10 petebacondarwin

A workaround is to use .fetch() on the durable object instead of rpc.

threepointone avatar Nov 07 '24 11:11 threepointone

any news ?

akazwz avatar Jan 04 '25 11:01 akazwz

any news ?

According to #7251 it was fixed (fix was merged) already... But I haven't tried it.

Chinoman10 avatar Jan 06 '25 08:01 Chinoman10

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

emily-shen avatar Jan 06 '25 10:01 emily-shen

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.

zhihengGet avatar Jan 07 '25 16:01 zhihengGet

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.
```

kylecarbs avatar May 06 '25 02:05 kylecarbs

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.

jcrowthe avatar May 09 '25 17:05 jcrowthe

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 avatar May 09 '25 18:05 petebacondarwin

@petebacondarwin is it possible to specify multiple configs with next-on-pages? I don't believe so from taking a look.

kylecarbs avatar May 10 '25 21:05 kylecarbs

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.

petebacondarwin avatar May 11 '25 13:05 petebacondarwin

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.

petebacondarwin avatar May 11 '25 13:05 petebacondarwin

I'm doing the fetch right now! I'll look at migrating, thank you :)

kylecarbs avatar May 11 '25 15:05 kylecarbs

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 :)

emily-shen avatar May 12 '25 13:05 emily-shen

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?

sassanh avatar May 30 '25 15:05 sassanh

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.

mgandolfi7 avatar Nov 06 '25 20:11 mgandolfi7

⚠️ 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#myMethod as Durable Object RPC is not yet supported between multiple wrangler dev sessions.


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.

josephbuchma avatar Nov 07 '25 10:11 josephbuchma