{"record":{"id":"95f8fc012f488387","repo":"withastro/astro","slug":"staticclientaddressnotavailable","errorCode":"StaticClientAddressNotAvailable","errorMessage":"`Astro.clientAddress` is only available on pages that are server-rendered.","messagePattern":"`Astro\\.clientAddress` is only available on pages that are server-rendered\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/fetch/fetch-state.ts","lineNumber":609,"sourceCode":"\t\tif (routeData.prerender) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...AstroErrorData.PrerenderClientAddressNotAvailable,\n\t\t\t\tmessage: AstroErrorData.PrerenderClientAddressNotAvailable.message(routeData.component),\n\t\t\t});\n\t\t}\n\n\t\tif (clientAddress) {\n\t\t\treturn clientAddress;\n\t\t}\n\n\t\tif (pipeline.adapterName) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...AstroErrorData.ClientAddressNotAvailable,\n\t\t\t\tmessage: AstroErrorData.ClientAddressNotAvailable.message(pipeline.adapterName),\n\t\t\t});\n\t\t}\n\n\t\tthrow new AstroError(AstroErrorData.StaticClientAddressNotAvailable);\n\t}\n\n\tgetCookies(): AstroCookies {\n\t\treturn this.cookies;\n\t}\n\n\tgetCsp(): APIContext['csp'] {\n\t\tconst state = this;\n\t\tconst { pipeline } = this;\n\t\tif (!pipeline.manifest.csp) {\n\t\t\tif (pipeline.runtimeMode === 'production') {\n\t\t\t\tpipeline.logger.warn(\n\t\t\t\t\t'csp',\n\t\t\t\t\t`context.csp was used when rendering the route ${colors.green(state.routeData!.route)}, but CSP was not configured. For more information, see https://docs.astro.build/en/reference/configuration-reference/#securitycsp`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/core/fetch/fetch-state.ts#L591-L627","documentation":"Thrown by getClientAddress() as the final fallback when the route is server-rendered, no adapter is configured, and clientAddress was never set. With no adapter and no stored address there is no source for the visitor IP at all, so reading Astro.clientAddress on a purely static/local setup is impossible.","triggerScenarios":"Running a server-rendered route via the dev server or a static build with no adapter, and accessing Astro.clientAddress. The throw fires after the adapterName check because pipeline.adapterName is falsy.","commonSituations":"Reading Astro.clientAddress during `astro dev` on a route that is on-demand but the project has no adapter installed yet; testing clientAddress logic locally before deploying; a project that is output 'static' but a single route is forced server-rendered.","solutions":["Install and configure an adapter that provides clientAddress before reading it.","Avoid Astro.clientAddress in code paths exercised during local dev without an adapter.","Fall back to request headers in dev/test environments where no adapter is present."],"exampleFix":"// before\nconst ip = Astro.clientAddress; // throws, no adapter configured\n\n// after\n// install: npx astro add node\nconst ip = Astro.clientAddress;","handlingStrategy":"validation","validationCode":"// Avoid clientAddress entirely when no adapter is configured.\nconst hasAdapter = Boolean((Astro as any).pipeline?.adapterName);\nconst ip = hasAdapter ? Astro.clientAddress : undefined;","typeGuard":"function hasAdapter(pipeline: { adapterName?: string }): boolean {\n  return Boolean(pipeline.adapterName);\n}","tryCatchPattern":"try {\n  ip = Astro.clientAddress;\n} catch (e) {\n  if (e instanceof Error && /server-rendered/i.test(e.message)) {\n    ip = undefined;\n  } else throw e;\n}","preventionTips":["Install an adapter before relying on clientAddress.","Skip clientAddress-dependent code in dev/test without an adapter.","Use feature flags gated on adapter presence."],"tags":["clientaddress","adapter","ssr","static"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}