{"record":{"id":"fb61337389208b79","repo":"anomalyco/sst","slug":"you-must-provide-a-worker-for-the-name-cron","errorCode":null,"errorMessage":"You must provide a \"worker\" for the \"${name}\" Cron component.","messagePattern":"You must provide a \"worker\" for the \"(.+?)\" Cron component\\.","errorType":"validation","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/cloudflare/cron.ts","lineNumber":164,"sourceCode":"    const parent = this;\n\n    const workerArgs = normalizeWorker();\n    const worker = createWorker();\n    const trigger = createTrigger();\n    this.worker = worker;\n    this.trigger = trigger;\n\n    function normalizeWorker() {\n      if (args.job && args.worker)\n        throw new VisibleError(\n          `You cannot provide both \"job\" and \"worker\" in the \"${name}\" Cron component. The \"job\" property has been deprecated. Use \"worker\" instead.`,\n        );\n      return args.worker ?? args.job;\n    }\n\n    function createWorker() {\n      if (!workerArgs)\n        throw new VisibleError(\n          `You must provide a \"worker\" for the \"${name}\" Cron component.`,\n        );\n      return workerBuilder(`${name}Handler`, workerArgs, undefined, undefined, args.accountId);\n    }\n\n    function createTrigger() {\n      return all([args.schedules]).apply(([schedules]) => {\n        return new cloudflare.WorkersCronTrigger(\n          ...transform(\n            args.transform?.trigger,\n            `${name}Trigger`,\n            {\n              accountId: args.accountId ?? DEFAULT_ACCOUNT_ID,\n              scriptName: worker.script.scriptName,\n              schedules: schedules.map((s) => ({ cron: s })),\n            },\n            { parent },\n          ),","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/cloudflare/cron.ts#L146-L182","documentation":"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.","triggerScenarios":"Creating `new sst.cloudflare.Cron(app, \"Cron\", { schedule: ... })` with no `worker` (and no `job`) property; workerArgs is undefined in createWorker.","commonSituations":"Deleting the `job`/`worker` block during migration and leaving an empty component; conditional args that evaluate to undefined; copy-pasting a schedule-only example.","solutions":["Add a `worker` property with the script/handler definition for the cron.","Remove the Cron component entirely if no work is needed.","Check that the args object passed to the component isn't conditionally dropping `worker`."],"exampleFix":"// before\nnew sst.cloudflare.Cron(app, \"Cron\", { schedule: \"0 * * * *\" });\n// after\nnew sst.cloudflare.Cron(app, \"Cron\", {\n  schedule: \"0 * * * *\",\n  worker: { scriptPath: \"./src/cron.ts\" },\n});","handlingStrategy":"validation","validationCode":"if (!cronArgs.worker && !cronArgs.job) throw new Error(\"Cron requires a 'worker' definition\");","typeGuard":"const hasWorker = (a: { worker?: unknown }) => a.worker != null;","tryCatchPattern":"try {\n  new sst.cloudflare.Cron(app, \"Cron\", cronArgs);\n} catch (e) {\n  if (String(e).includes('must provide a \"worker\"')) console.error(\"Add a worker property to the Cron\");\n  else throw e;\n}","preventionTips":["Always pair `schedule` with a `worker` in Cron components.","Watch for conditional args spreading that drops `worker`.","Type the component args so `worker` is required."],"tags":["cloudflare","cron","missing-argument","sst-config"],"backgroundTag":"missing-required-property","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}