{"record":{"id":"33d9a3d1821dca5f","repo":"anomalyco/sst","slug":"could-not-find-hosted-zone-for-domain-inputs-dom","errorCode":null,"errorMessage":"Could not find hosted zone for domain ${inputs.domain}","messagePattern":"Could not find hosted zone for domain (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"platform/src/components/cloudflare/providers/zone-lookup.ts","lineNumber":60,"sourceCode":"  ): Promise<{ zoneId: string; zoneName: string }> {\n    try {\n      const qs = new URLSearchParams({\n        per_page: \"50\",\n        page: String(page),\n        \"account.id\": inputs.accountId,\n      }).toString();\n      const ret = await cfFetch<{ name: string; id: string }[]>(\n        `/zones?${qs}`,\n        { headers: { \"Content-Type\": \"application/json\" } },\n      );\n      const zone = ret.result.find(\n        // ensure `example.com` does not match `myexample.com`\n        (z) => inputs.domain === z.name || inputs.domain.endsWith(`.${z.name}`),\n      );\n      if (zone) return { zoneId: zone.id, zoneName: zone.name };\n\n      if (ret.result.length < ret.result_info!.per_page)\n        throw new Error(\n          `Could not find hosted zone for domain ${inputs.domain}`,\n        );\n\n      return this.lookup(inputs, page + 1);\n    } catch (error: any) {\n      console.log(error);\n      throw error;\n    }\n  }\n}\n\nexport class ZoneLookup extends dynamic.Resource {\n  constructor(\n    name: string,\n    args: ZoneLookupInputs,\n    opts?: CustomResourceOptions,\n  ) {\n    super(","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/cloudflare/providers/zone-lookup.ts#L42-L78","documentation":"Before binding a domain, SST queries Cloudflare's zone list API to find the hosted zone matching the domain. If all pages of zones are exhausted without a match, it throws because Cloudflare cannot route a domain it doesn't manage.","triggerScenarios":"lookup() paginates through account zones and no zone name equals or is a parent of `inputs.domain` (exact match or subdomain ending in `.zonename`); thrown when the last page is reached (`result.length < per_page`) with no match.","commonSituations":"Domain's DNS is hosted elsewhere (not in the API-token's Cloudflare account); API token lacks Zone:Read permission so zones list is empty; typo in the domain; subdomain whose parent zone isn't in this account; zone not yet added to Cloudflare.","solutions":["Add the domain (parent zone) to your Cloudflare account and update nameservers.","Check the Cloudflare API token has Zone:Read permission and covers the right account.","Verify the domain string in your sst.config.ts for typos and that the parent zone exists in the account."],"exampleFix":"// before\nconst zone = cloudflare.getZoneOutput({ name: \"app.example.com\" }); // parent zone not in account\n// after — ensure example.com is added to the Cloudflare account first, then:\ndns: cloudflare.dns({ domain: \"app.example.com\" })","handlingStrategy":"retry","validationCode":"// pre-check via Cloudflare API before deploy\nconst res = await fetch(`https://api.cloudflare.com/client/v4/zones?name=${parentDomain}`, { headers: { Authorization: `Bearer ${token}` } });\nconst json = await res.json();\nif (!json.result?.length) throw new Error(\"Parent zone not in this Cloudflare account\");","typeGuard":null,"tryCatchPattern":"try {\n  new sst.cloudflare.StaticSite(app, \"Site\", { domain: { name: \"app.example.com\", dns: cloudflare.dns() } });\n} catch (e) {\n  if (String(e).includes(\"Could not find hosted zone\")) console.error(\"Add the zone to Cloudflare or fix the API token\");\n  else throw e;\n}","preventionTips":["Add the parent zone to your Cloudflare account before binding subdomains.","Grant the API token Zone:Read on the right account.","Double-check domain spelling in sst.config.ts.","Verify DNS for the domain is actually served by Cloudflare."],"tags":["cloudflare","dns","hosted-zone","domain","api-token"],"backgroundTag":"hosted-zone-not-found","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}