cloudflare-docs icon indicating copy to clipboard operation
cloudflare-docs copied to clipboard

Update _service-binding-rpc-example.md

Open PeterHindes opened this issue 1 year ago • 2 comments
trafficstars

Update _service-binding-rpc-example.md to reflect the fact that newer compatibility dates break the example in the docs.

Alternatively workers could be fixed to not produce the following error with the current example, or the example changed.

 ⛅️ wrangler 3.61.0
-------------------

▲ [WARNING] The entrypoint src/index.js 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...


⎔ Starting local server...
[wrangler:inf] Ready on http://localhost:8787
✘ [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.


✘ [ERROR] service core:user:service-test: Uncaught Error: Dynamic require of "cloudflare:workers" is not supported

    at null.<anonymous> (core:user:service-test:7:11)
    at null.<anonymous> (core:user:service-test:273:35)
    at null.<anonymous> (core:user:service-test:279:3)```

PeterHindes avatar Jun 20 '24 22:06 PeterHindes

update, it seems like the error happens when

export default {
  fetch() {

is not in the service. So this might be a more accurate change to make. Or workers could be fixed to not require that for services that dont interface with the web.

PeterHindes avatar Jun 20 '24 23:06 PeterHindes

Thanks for creating this PR! As you found, in your follow-up comment, this error occurs when we cannot detect your module as ESM over CJS (and we rely on the export there to do so). We plan to remove this requirement and support Workers which don't have a default export or handler, but don't yet have a timeline we can commit to for that. In the interim, perhaps this PR could be changed to instead be a note calling out that, even if only defining an named entrypoint, a Worker still requires a default export with at least one handler registered?

GregBrimble avatar Jun 21 '24 10:06 GregBrimble

👋Hi there, we’re going to close this PR. All PRs prior to August 12 need to be reworked due to the platform migration to Astro.

KimJ15 avatar Sep 27 '24 15:09 KimJ15