cloudflare / cloudflare/workers-sdk

🐛 BUG: `getPlatformProxy` invariant behavior with RPC targets

Open
#8,510 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
187

Description

### Which Cloudflare product(s) does this pertain to?

Miniflare

### What versions are you using?

4.0.0 [Wrangler]

### What operating system and version are you using?

Mac Sonoma 14.5

### Please provide a link to a minimal reproduction

https://github.com/hntrl/durable-object-rpc-repro/tree/platform-proxy-issue

### Describe the Bug

In local dev, I'm trying to access a method on an rpc target through a service binding that's defined on another worker using getPlatformProxy, but i'm running into some invariant behaviors when accessing the target. If I try to call a method on the target using the proxy, I get an unexpected TypeError. I'm able to access the method in the way I'm describing if I'm using it on a separate worker with the same bindings and run it using wrangler dev.

There is a repro attached to this issue, but just for convenience sake here's also a minimal example:

**workerA**
---
```toml
# workerA/wrangler.toml

#:schema node_modules/wrangler/config-schema.json
name = "durable-object-repro-a"
main = "src/worker.ts"
compatibility_date = "2024-12-18"
```
```ts
// workerA/src/worker.ts

import { RpcTarget, WorkerEntrypoint } from "cloudflare:workers";

class FooTarget extends RpcTarget {
async getFoo() {
return "foo";
}
}

export default class WorkerA extends WorkerEntrypoint {
get foo() {
return new FooTarget();
}
getBar() {
return "bar";
}
}
```

**proxy**
---
```toml
# proxy/wrangler.toml

#:schema node_modules/wrangler/config-schema.json
name = "durable-object-repro-proxy"
compatibility_date = "2024-11-18"
main = "src/index.ts"

services = [{ binding = "WORKER_A", service = "durable-object-repro-a" }]
```
```ts
// proxy/src/index.ts

// @ts-nocheck

import { getPlatformProxy } from "wrangler";

async function main() {
const proxy = await getPlatformProxy();

console.log(await proxy.env.WORKER_A.foo);
// [Function: foo]

console.log(await proxy.env.WORKER_A.getBar());
// "bar"

console.log(await proxy.env.WORKER_A.foo.getFoo());
// TypeError: proxy.env.WORKER_A.foo.getFoo is not a function
}

main();
```

### Please provide any relevant error logs

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by running the minimal reproduction from proxy/src/index.ts with the service binding in proxy/wrangler.toml, then compare it with the WorkerEntrypoint and RpcTarget definitions in workerA/src/worker.ts. Done means getPlatformProxy preserves the RPC target so proxy.env.WORKER_A.foo.getFoo() returns "foo" rather than a TypeError, while getBar() continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.