anomalyco/sst · error · VisibleError

You must provide a "worker" for the "${name}" Cron component

Error message

You must provide a "worker" for the "${name}" Cron component.

What it means

The Cron component requires a handler definition, but after normalization neither `worker` nor the deprecated `job` was provided. SST cannot build a cron without something to run.

Source

Thrown at platform/src/components/cloudflare/cron.ts:164

    const parent = this;

    const workerArgs = normalizeWorker();
    const worker = createWorker();
    const trigger = createTrigger();
    this.worker = worker;
    this.trigger = trigger;

    function normalizeWorker() {
      if (args.job && args.worker)
        throw new VisibleError(
          `You cannot provide both "job" and "worker" in the "${name}" Cron component. The "job" property has been deprecated. Use "worker" instead.`,
        );
      return args.worker ?? args.job;
    }

    function createWorker() {
      if (!workerArgs)
        throw new VisibleError(
          `You must provide a "worker" for the "${name}" Cron component.`,
        );
      return workerBuilder(`${name}Handler`, workerArgs, undefined, undefined, args.accountId);
    }

    function createTrigger() {
      return all([args.schedules]).apply(([schedules]) => {
        return new cloudflare.WorkersCronTrigger(
          ...transform(
            args.transform?.trigger,
            `${name}Trigger`,
            {
              accountId: args.accountId ?? DEFAULT_ACCOUNT_ID,
              scriptName: worker.script.scriptName,
              schedules: schedules.map((s) => ({ cron: s })),
            },
            { parent },
          ),

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Add a `worker` property with the script/handler definition for the cron.
  2. Remove the Cron component entirely if no work is needed.
  3. Check that the args object passed to the component isn't conditionally dropping `worker`.

Example fix

// before
new sst.cloudflare.Cron(app, "Cron", { schedule: "0 * * * *" });
// after
new sst.cloudflare.Cron(app, "Cron", {
  schedule: "0 * * * *",
  worker: { scriptPath: "./src/cron.ts" },
});
Defensive patterns

Strategy: validation

Validate before calling

if (!cronArgs.worker && !cronArgs.job) throw new Error("Cron requires a 'worker' definition");

Type guard

const hasWorker = (a: { worker?: unknown }) => a.worker != null;

Try / catch

try {
  new sst.cloudflare.Cron(app, "Cron", cronArgs);
} catch (e) {
  if (String(e).includes('must provide a "worker"')) console.error("Add a worker property to the Cron");
  else throw e;
}

Prevention

When it happens

Trigger: Creating `new sst.cloudflare.Cron(app, "Cron", { schedule: ... })` with no `worker` (and no `job`) property; workerArgs is undefined in createWorker.

Common situations: Deleting the `job`/`worker` block during migration and leaving an empty component; conditional args that evaluate to undefined; copy-pasting a schedule-only example.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/fb61337389208b79. Report an issue: GitHub.