denoland/deno · error · TypeError
Cannot create cron job, a schedule is required: received…
Error message
Cannot create cron job, a schedule is required: received 'undefined'
What it means
Deno.cron's second parameter - a cron expression string or a structured schedule object - is mandatory. The guard is `schedule === undefined`, throwing before any parsing happens.
Solutions
- Provide a cron string ('*/5 * * * *') or an object ({ hour: { every: 2 } })
- Fix argument order: (name, schedule, handler)
- Default or validate config-derived schedules before calling Deno.cron
Example fix
// before
Deno.cron("n", undefined, fn);
// after
Deno.cron("n", "*/5 * * * *", fn); Defensive patterns
Strategy: validation
Validate before calling
if (schedule === undefined) {
throw new TypeError("cron schedule is required");
} Prevention
- Always pass a cron string or schedule object as the second argument
- Validate config-loaded schedules before calling Deno.cron
- Let TypeScript check the Deno.CronSchedule type at compile time
When it happens
Trigger: `Deno.cron("n", undefined, fn)`; calling with (name, handler) argument order so the schedule slot receives a function reference is NOT caught here (a function is defined) - the pure undefined case is, e.g. schedule loaded from config that is missing.
Common situations: Schedule built from config/env that failed to resolve; accidentally passing the handler as the second argument and nothing third; destructuring a schedule object that was renamed.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Cannot create cron job, a unique name is required: received…
- Cannot create cron job: a handler is required
- Cannot create cron job, a single handler is required: two…
- Invalid cron schedule: start=
- ERR_MISSING_ARGS
AI-assisted analysis of denoland/deno@a961cdec3b (2026-08-20).
Data as JSON: /api/errors/11f2424599159377.
Report an issue: GitHub.
Appendix: source
Thrown at ext/cron/01_cron.ts:122
" " + formatToCronSchedule(dayOfWeek);
}
}
function cron(
name: string,
schedule: string | Deno.CronSchedule,
handlerOrOptions1:
| (() => Promise<void> | void)
| ({ backoffSchedule?: number[]; signal?: AbortSignal }),
handler2?: () => Promise<void> | void,
) {
if (name === undefined) {
throw new TypeError(
"Cannot create cron job, a unique name is required: received 'undefined'",
);
}
if (schedule === undefined) {
throw new TypeError(
"Cannot create cron job, a schedule is required: received 'undefined'",
);
}
schedule = parseScheduleToString(schedule);
let handler: () => Promise<void> | void;
let options:
| { backoffSchedule?: number[]; signal?: AbortSignal }
| undefined = undefined;
if (typeof handlerOrOptions1 === "function") {
handler = handlerOrOptions1;
if (handler2 !== undefined) {
throw new TypeError(
"Cannot create cron job, a single handler is required: two handlers were specified",
);
}View on GitHub (pinned to a961cdec3b)