anomalyco/sst · error · VisibleError

Cannot use both `routes` and `.routeBucket()` function to ad

Error message

Cannot use both `routes` and `.routeBucket()` function to add routes.

What it means

Same mutual-exclusion rule as `route()`: the `.routeBucket()` method throws this VisibleError when the Router was constructed with the inline `routes` prop, since the two route-adding APIs cannot be combined.

Source

Thrown at platform/src/components/aws/router.ts:2625

   *   rewrite: {
   *     regex: "^/files/(.*)$",
   *     to: "/$1"
   *   }
   * });
   * ```
   *
   * Here something like `/files/logo.png` will be routed to
   * `/logo.png`.
   */
  public routeBucket(
    pattern: Input<string>,
    bucket: Input<Bucket>,
    args?: Input<RouterBucketRouteArgs>,
  ) {
    all([pattern, args, this.hasInlineRoutes]).apply(
      ([pattern, args, hasInlineRoutes]) => {
        if (hasInlineRoutes)
          throw new VisibleError(
            "Cannot use both `routes` and `.routeBucket()` function to add routes.",
          );

        new RouterBucketRoute(
          `${this.constructorName}Route${pattern}`,
          {
            store: this.kvStoreArn!,
            routerNamespace: this.kvNamespace!,
            pattern,
            bucket,
            routeArgs: args,
          },
          { provider: this.constructorOpts.provider },
        );
      },
    );
  }

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Convert all routes to lazy calls: use `.routeBucket()` for buckets and `.route()` for URLs, removing the inline `routes` prop
  2. Or declare the bucket route inline inside the `routes` map instead of calling `.routeBucket()`

Example fix

// before
const r = new Router($app, "R", { routes: { "/*": "https://example.com" } });
r.routeBucket("/static/*", myBucket);
// after
const r = new Router($app, "R", {});
r.route("/*", "https://example.com");
r.routeBucket("/static/*", myBucket);
Defensive patterns

Strategy: validation

Validate before calling

if (routerArgs.routes && needsBucketRoute)
  throw new Error("Cannot mix `routes` prop with .routeBucket() calls");

Try / catch

try {
  const r = new Router(ctx, "R", { routes });
  r.routeBucket("/static/*", bucket);
} catch (e) {
  if (String(e).includes(".routeBucket() function")) console.error("Pick one route API");
  throw e;
}

Prevention

When it happens

Trigger: `new Router(..., { routes: {...} })` followed by `router.routeBucket(pattern, bucket)`.

Common situations: Adding a static-site bucket route to an existing Router that was declared with inline routes; code that mixes examples of both APIs.

Related errors


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