Workers Subworker Service Binding fails to deploy (code: 10068)

Okay, so I am attempting to follow the guide here: Service bindings - Runtime APIs · Cloudflare Workers docs

Specifically, this method: Service bindings - RPC (WorkerEntrypoint) · Cloudflare Workers docs

The guide advises us to structure our code like so:

import { WorkerEntrypoint } from "cloudflare:workers";

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

The problem is, when I attempt to “wrangler deploy” this, I receive the following error:

✘ [ERROR] A request to the Cloudflare API (/{redact}/{redact}/workers/scripts/{redact}) failed.

  The uploaded script has no registered event handlers. [code: 10068]
  
  If you think this is a bug, please open an issue at:
  https://github.com/cloudflare/workers-sdk/issues/new/choose

But, as far as I can reckon, the only difference between my code and the listed example is that I’m using typescript instead of javascript…

import { WorkerEntrypoint } from "cloudflare:workers";

export default class extends WorkerEntrypoint {
	async add(a: number, b: number): Promise<number> {
		return a + b;
	  }
}

The above fails with the same exact error. I’m just… curious what’s wrong.

1 Like

You need to add a fetch() method to your class.

import { WorkerEntrypoint } from "cloudflare:workers";

export default class extends WorkerEntrypoint {
  async fetch() {
    return new Response(null, {status: 404});
  }

  async add(a: number, b: number): Promise<number> {
    return a + b;
  }
}

There is a much better example here: Service bindings - RPC (WorkerEntrypoint) · Cloudflare Workers docs