cloudflare / cloudflare/cloudflare-docs

Errors in Workers RPC docs

Open
#31,154 1 comment 0 reactions 7 assignees Claimed by @WalshyDev View on GitHub
content:edit documentation product:workers stale
Dominant language
MDX
Stars
5.2k
Forks
16.7k
Avg merge
2d 6h
Merged PRs (30d)
337

Description

### Existing documentation URL(s)

- https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/rpc/#example

### What changes are you suggesting?

I tried to follow the most basic example at the top of the page, using Typescript and hit the following problems that prevented the example working. I had applied the approach in the docs to a much larger project without success and it was only after I tried the minimal example in the docs I realised the docs appear to be wrong.

* `wrangler.jsonc` needs `"compatibility_date"` or `wrangler types` will not work. The example files don't have `"compatibility_date"`.
* It's not clear what directories the 2 workers go in to avoid having 2 `wrangler.jsonc` files in the same directory
* I put mine in directories `a` and `b`
* `wrangler types` generates `WORKER_B: Fetcher` so worker A will not typecheck: it will not find the `.add` method
* I added `"entrypoint": "default"` for service B to worker A's `wrangler.jsonc`, then `wrangler types` generated `WORKER_B: Service`
* This is better but will still not typecheck because it needs to be generated with the type parameter for `Service` so the `.add` method is made visible
* The only way I could find to make it typecheck was write the `Env` interface myself:
* `interface Env { WORKER_B: Service }`
* Typechecking is now OK with calling the `.add` method but fails at `return new Response(result)` because result (number) is not a type `Response` accepts
* I coerced this to a string
* Ran with `wrangler dev -c a/wrangler.jsonc -c b/wrangler.jsonc`
* Got an error `Worker "core:user:worker_a"'s binding "WORKER_B" refers to service "core:user:worker_b" with a named entrypoint "default", but "core:user:worker_b" has no such named entrypoint.`
* So I removed `"entrypoint": "default"`
* It nows runs
* With the above changes, the `fetch` method on worker B is redundant and can be removed.

My wrangler version is 4.95.0 (the latest at the time of writing).

Can you check this example in the documentation and amend it so it works, or if there is some important step I missed, call that out?

### Additional information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.