Trying to add a cron job to my worker.

I have an existing worker that uses Hono to expose some API endpoints:

const app = new Hono();
...
export default app;


I am trying to add a cron job to this worker but I am continuously getting either a
"Handler does not export a scheduled() function" error or a,
"worker.fetch is not a function" error.

I am defining my scheduled.ts worker like this:

export default {

  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    // ...
  },

  async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
    // ...
  }


and then updating my main index.ts export like this:

export default {
    app,
    scheduled,
    fetch
}



But at runtime I am getting the error:
Error: Handler does not export a fetch() function.
Was this page helpful?