Skip to content

Errors in Workers RPC docs #31154

@duncanpierce

Description

@duncanpierce

Existing documentation URL(s)

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<import("../b/workerB").default> }
  • 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

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions