anomalyco/sst · error · VisibleError

You must provide either a function or a task in the

Error message

You must provide either a function or a task in the "${name}" CronV2 component.

What it means

CronV2 requires exactly one schedule target. This error is thrown in normalizeTargets when neither a `function`/`job` nor a `task` is provided, so the schedule would be created with nothing to invoke.

Solutions

  1. Add a `function` property pointing to a function/linkable handler
  2. Add a `task` property pointing to an ECS task if the job should run in ECS
  3. If the cron is not yet implemented, comment out the whole CronV2 component until the handler exists

Example fix

// before
new sst.aws.CronV2("MyCron", {
  schedule: "rate(1 day)",
});
// after
new sst.aws.CronV2("MyCron", {
  schedule: "rate(1 day)",
  function: handler,
});
Defensive patterns

Strategy: validation

Validate before calling

function validateCronV2Target(args: sst.aws.CronV2Args) {
  if (!args.function && !args.job && !args.task)
    throw new Error("CronV2 requires a 'function' or 'task' target");
}

Type guard

function hasTarget(args: { function?: unknown; job?: unknown; task?: unknown }): boolean {
  return Boolean(args.function ?? args.job ?? args.task);
}

Try / catch

try {
  new sst.aws.CronV2("MyCron", args);
} catch (e) {
  if (e instanceof Error && e.message.includes("must provide either a function or a task")) {
    console.error("Add a function or task target to the cron");
  } else throw e;
}

Prevention

When it happens

Trigger: `new sst.aws.CronV2(name, { schedule })` with no `function`, `job`, or `task` in args — e.g. an empty args object or all target keys commented out.

Common situations: Scaffolding a cron and forgetting to wire the handler; commenting out the function while debugging; a dynamically built args object that ends up empty due to a false conditional.

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 anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/96a1bb17c2fdd424. Report an issue: GitHub.

Appendix: source

Thrown at platform/src/components/aws/cron-v2.ts:340

    this._schedule = schedule;

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

      const input = args.function ?? args.job;
      return input ? output(input) : undefined;
    }

    function normalizeTargets() {
      if (fnArgs && args.task)
        throw new VisibleError(
          `You cannot provide both a function and a task in the "${name}" CronV2 component.`,
        );
      if (!fnArgs && !args.task)
        throw new VisibleError(
          `You must provide either a function or a task in the "${name}" CronV2 component.`,
        );
    }

    function createFunction() {
      if (!fnArgs) return;

      return fnArgs.apply((fnArgs) =>
        functionBuilder(`${name}Handler`, fnArgs, {}, undefined, {
          parent,
        }),
      );
    }

    function createRole() {
      if (fn) {
        return new iam.Role(
          ...transform(

View on GitHub (pinned to a0bd20f762)