denoland/deno · error · TypeError

Cannot create cron job, a unique name is required: received…

Error message

Cannot create cron job, a unique name is required: received 'undefined'

What it means

Deno.cron's first parameter is the unique job name (used to deduplicate jobs across runs of the same code). The check is `name === undefined`, so a completely missing/undefined name throws immediately, while an empty string would pass this guard but still defeats deduplication.

Solutions

  1. Pass a stable, unique name string first: `Deno.cron('my-job', schedule, handler)`
  2. If the name comes from config, default it: `Deno.cron(name ?? 'my-job', ...)`
  3. Re-check the argument order: (name, schedule, handler) or (name, schedule, options, handler)

Example fix

// before
Deno.cron(process.env.JOB_NAME, "* * * * *", fn); // env var unset -> undefined

// after
Deno.cron(Deno.env.get("JOB_NAME") ?? "fallback-job", "* * * * *", fn);
Defensive patterns

Strategy: validation

Validate before calling

if (name === undefined) {
  throw new TypeError("cron name is required");
}

Prevention

When it happens

Trigger: `Deno.cron(undefined, "* * * * *", fn)` - typically a name variable that failed to initialize, or arguments passed in the wrong order (schedule first, name second).

Common situations: Name read from an env var or config key that is absent; refactoring that swapped the name and schedule parameters; generated job code where the name template produced undefined.

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


AI-assisted analysis of denoland/deno@a961cdec3b (2026-08-20). Data as JSON: /api/errors/06775de36da310a4. Report an issue: GitHub.

Appendix: source

Thrown at ext/cron/01_cron.ts:117

    return formatToCronSchedule(minute) +
      " " + formatToCronSchedule(hour) +
      " " + formatToCronSchedule(dayOfMonth) +
      " " + formatToCronSchedule(month) +
      " " + 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;

View on GitHub (pinned to a961cdec3b)