{"record":{"id":"5c4085488645bded","repo":"withastro/astro","slug":"astro-locals-runtime-env-has-been-removed-in-astro","errorCode":null,"errorMessage":"Astro.locals.runtime.env has been removed in Astro v6. Use 'import { env } from \"cloudflare:workers\"' instead.","messagePattern":"Astro\\.locals\\.runtime\\.env has been removed in Astro v6\\. Use 'import (.+?) from \"cloudflare:workers\"' instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/integrations/cloudflare/src/utils/cf-helpers.ts","lineNumber":72,"sourceCode":"export function createErrorPageFetch(env: Env): (url: string) => Promise<Response> {\n\treturn async (url: string) => {\n\t\treturn env.ASSETS.fetch(url.replace(/\\.html$/, '')) as unknown as Response;\n\t};\n}\n\n/**\n * Creates the Cloudflare-specific locals object with `cfContext`\n * and deprecated `runtime` property getters.\n */\nexport function createLocals(ctx: ExecutionContext): Runtime {\n\tconst locals: Runtime = {\n\t\tcfContext: ctx,\n\t};\n\tObject.defineProperty(locals, 'runtime', {\n\t\tenumerable: false,\n\t\tvalue: {\n\t\t\tget env(): never {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Astro.locals.runtime.env has been removed in Astro v6. Use 'import { env } from \"cloudflare:workers\"' instead.`,\n\t\t\t\t);\n\t\t\t},\n\t\t\tget cf(): never {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Astro.locals.runtime.cf has been removed in Astro v6. Use 'Astro.request.cf' instead.`,\n\t\t\t\t);\n\t\t\t},\n\t\t\tget caches(): never {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Astro.locals.runtime.caches has been removed in Astro v6. Use the global 'caches' object instead.`,\n\t\t\t\t);\n\t\t\t},\n\t\t\tget ctx(): never {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Astro.locals.runtime.ctx has been removed in Astro v6. Use 'Astro.locals.cfContext' instead.`,\n\t\t\t\t);\n\t\t\t},","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/integrations/cloudflare/src/utils/cf-helpers.ts#L54-L90","documentation":"Astro v6 removed the `Astro.locals.runtime` compatibility object that older @astrojs/cloudflare versions exposed. The adapter now defines a non-enumerable `runtime` property whose `env` getter throws with migration instructions instead of silently returning data. Hitting it means pre-v6 adapter code is still reading environment bindings from `Astro.locals.runtime.env`.","triggerScenarios":"After upgrading to Astro v6 (or installing the v6-era adapter), any page/middleware/API route executing `Astro.locals.runtime.env.MY_VAR` triggers the getter and throws at request or prerender time.","commonSituations":"Upgrading an Astro v5 Cloudflare project to v6 without migrating runtime access; copying older snippet/tutorial code that uses locals.runtime.env into a v6 project.","solutions":["Replace all reads with the module-level import: `import { env } from 'cloudflare:workers';` then use `env.MY_VAR`.","Search the codebase for `locals.runtime` and migrate every remaining occurrence (cf, caches, ctx have their own messages).","Use the official `astro upgrade` flow / upgrade guide which covers adapter migrations.","If migration is not possible yet, downgrade astro and @astrojs/cloudflare to the last v5-compatible pair."],"exampleFix":"// before\nconst { DB } = Astro.locals.runtime.env;\n\n// after\nimport { env } from 'cloudflare:workers';\nconst { DB } = env;","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Returns legacy env bindings if present, else undefined — never triggers the trap getter\nimport { env } from 'cloudflare:workers';\nfunction safeEnv(locals: App.Locals): Record<string, unknown> | undefined {\n  const runtime = (locals as Record<string, unknown>).runtime;\n  if (!runtime || typeof runtime !== 'object') return undefined;\n  try {\n    return (runtime as { env: unknown }).env as Record<string, unknown>;\n  } catch {\n    return undefined; // v6 trap getter threw — use `env` instead\n  }\n}","tryCatchPattern":null,"preventionTips":["Grep the codebase for `locals.runtime` as part of every major Astro upgrade.","Adopt `import { env } from 'cloudflare:workers'` at module scope so access is static, not request-time.","Run the official `astro upgrade` codemods and the adapter migration guide together."],"tags":["cloudflare","astro-v6","breaking-change","env-vars","migration"],"backgroundTag":"removed-api-migration","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}