Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worker service-binding using RPC example incomplete #17421

Open
rozenmd opened this issue Oct 9, 2024 · 0 comments
Open

Worker service-binding using RPC example incomplete #17421

rozenmd opened this issue Oct 9, 2024 · 0 comments
Assignees
Labels
content:edit Request for content edits documentation Documentation edits product:workers Related to Workers product

Comments

@rozenmd
Copy link
Contributor

rozenmd commented Oct 9, 2024

Existing documentation URL(s)

https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#example--build-your-first-service-binding-using-rpc

What changes are you suggesting?

The example is too light on information (we should link to the reference doc for Service Workers in the example), and the example doesn't work as-is.

If you attempt to deploy a Worker defined as:

import { WorkerEntrypoint } from "cloudflare:workers";

export class WorkerB extends WorkerEntrypoint {
  async add(a, b) { return a + b; }
}

Wrangler throws:

▲ [WARNING] The entrypoint src/index.ts has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using "service-worker" format...


✘ [ERROR] Unexpected external import of "node:buffer", "node:events", "node:stream", and "node:timers/promises". Imports are not valid in a Service Worker format Worker.
Did you mean to create a Module Worker?
If so, try adding `export default { ... }` in your entry-point

I had to find https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/rpc/#the-workerentrypoint-class to make it work, where it defines it as:

import { WorkerEntrypoint } from "cloudflare:workers";

export default class extends WorkerEntrypoint {
  async add(a, b) { return a + b; }
}

Additional information

No response

@rozenmd rozenmd added documentation Documentation edits content:edit Request for content edits labels Oct 9, 2024
@github-actions github-actions bot added the product:workers Related to Workers product label Oct 9, 2024
rts-rob added a commit that referenced this issue Nov 14, 2024
… to make the code sample work.

Partially addresses issue #17421.

Signed-off-by: Rob Sutter <[email protected]>
rts-rob added a commit that referenced this issue Nov 16, 2024
… to make the code sample work. (#18163)

Partially addresses issue #17421.

Signed-off-by: Rob Sutter <[email protected]>
harshil1712 pushed a commit that referenced this issue Dec 3, 2024
… to make the code sample work. (#18163)

Partially addresses issue #17421.

Signed-off-by: Rob Sutter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content:edit Request for content edits documentation Documentation edits product:workers Related to Workers product
Projects
None yet
Development

No branches or pull requests

5 participants