`wrangler dev --local` says I don't have a scheduled() function but I clearly have one

export default {
async scheduled(
controller: ScheduledController,
env: Env,
ctx: ExecutionContext,
): Promise<void> {
console.log(`Hello World!`);
},
};
export default {
async scheduled(
controller: ScheduledController,
env: Env,
ctx: ExecutionContext,
): Promise<void> {
console.log(`Hello World!`);
},
};
2 Replies
codebam
codebamOP3w ago
I just followed the instructions in the comment
/**
* Welcome to Cloudflare Workers! This is your first scheduled worker.
*
* - Run `wrangler dev --local` in your terminal to start a development server
* - Run `curl "http://localhost:8787/cdn-cgi/mf/scheduled"` to trigger the scheduled event
* - Go back to the console to see what your worker has logged
* - Update the Cron trigger in wrangler.toml (see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers)
* - Run `wrangler deploy --name my-worker` to deploy your worker
*
* Learn more at https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/
*/
/**
* Welcome to Cloudflare Workers! This is your first scheduled worker.
*
* - Run `wrangler dev --local` in your terminal to start a development server
* - Run `curl "http://localhost:8787/cdn-cgi/mf/scheduled"` to trigger the scheduled event
* - Go back to the console to see what your worker has logged
* - Update the Cron trigger in wrangler.toml (see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers)
* - Run `wrangler deploy --name my-worker` to deploy your worker
*
* Learn more at https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/
*/
I get the same error with the default worker it generates this is a bug ✘ [ERROR] Received a ScheduledEvent but we lack a handler for ScheduledEvents (a.k.a. Cron Triggers). Did you remember to export a scheduled() function?
rdutton
rdutton3w ago
Reading the docs they mention running: npx wrangler dev --test-scheduled to test crons.

Did you find this page helpful?