{"record":{"id":"aab0649c1b6a3ec8","repo":"anomalyco/sst","slug":"cannot-use-both-routes-and-routebucket-func","errorCode":null,"errorMessage":"Cannot use both `routes` and `.routeBucket()` function to add routes.","messagePattern":"Cannot use both `routes` and `\\.routeBucket\\(\\)` function to add routes\\.","errorType":"exception","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/router.ts","lineNumber":2625,"sourceCode":"   *   rewrite: {\n   *     regex: \"^/files/(.*)$\",\n   *     to: \"/$1\"\n   *   }\n   * });\n   * ```\n   *\n   * Here something like `/files/logo.png` will be routed to\n   * `/logo.png`.\n   */\n  public routeBucket(\n    pattern: Input<string>,\n    bucket: Input<Bucket>,\n    args?: Input<RouterBucketRouteArgs>,\n  ) {\n    all([pattern, args, this.hasInlineRoutes]).apply(\n      ([pattern, args, hasInlineRoutes]) => {\n        if (hasInlineRoutes)\n          throw new VisibleError(\n            \"Cannot use both `routes` and `.routeBucket()` function to add routes.\",\n          );\n\n        new RouterBucketRoute(\n          `${this.constructorName}Route${pattern}`,\n          {\n            store: this.kvStoreArn!,\n            routerNamespace: this.kvNamespace!,\n            pattern,\n            bucket,\n            routeArgs: args,\n          },\n          { provider: this.constructorOpts.provider },\n        );\n      },\n    );\n  }\n","sourceCodeStart":2607,"sourceCodeEnd":2643,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/router.ts#L2607-L2643","documentation":"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.","triggerScenarios":"`new Router(..., { routes: {...} })` followed by `router.routeBucket(pattern, bucket)`.","commonSituations":"Adding a static-site bucket route to an existing Router that was declared with inline routes; code that mixes examples of both APIs.","solutions":["Convert all routes to lazy calls: use `.routeBucket()` for buckets and `.route()` for URLs, removing the inline `routes` prop","Or declare the bucket route inline inside the `routes` map instead of calling `.routeBucket()`"],"exampleFix":"// before\nconst r = new Router($app, \"R\", { routes: { \"/*\": \"https://example.com\" } });\nr.routeBucket(\"/static/*\", myBucket);\n// after\nconst r = new Router($app, \"R\", {});\nr.route(\"/*\", \"https://example.com\");\nr.routeBucket(\"/static/*\", myBucket);","handlingStrategy":"validation","validationCode":"if (routerArgs.routes && needsBucketRoute)\n  throw new Error(\"Cannot mix `routes` prop with .routeBucket() calls\");","typeGuard":null,"tryCatchPattern":"try {\n  const r = new Router(ctx, \"R\", { routes });\n  r.routeBucket(\"/static/*\", bucket);\n} catch (e) {\n  if (String(e).includes(\".routeBucket() function\")) console.error(\"Pick one route API\");\n  throw e;\n}","preventionTips":["Choose the lazy route API when any route will be added outside the constructor","Express bucket routes inline as { bucket } entries if staying with the routes prop","Review constructor args and later .route* calls together in code review"],"tags":["router","api-misuse","config-validation","sst"],"backgroundTag":"incompatible-component-options","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}