withastro/astro · warning
Astro.site inside getStaticPaths is deprecated and will be r
Error message
Astro.site inside getStaticPaths is deprecated and will be removed in a future major version of Astro. Use import.meta.env.SITE instead
What it means
Inside getStaticPaths, Astro hands you a limited mock of the Astro global built by createAstro(). Reading Astro.site from that mock still returns the configured site (or undefined), but the property is deprecated: the getter logs a console.warn on every access and the source is explicitly marked to throw in Astro 7. The supported replacement is the SITE environment variable available to the same module via import.meta.env.
Source
Thrown at packages/astro/src/runtime/server/astro-global.ts:19
import { ASTRO_GENERATOR } from '../../core/constants.js';
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
import type { AstroGlobal } from '../../types/public/context.js';
function createError(name: string) {
return new AstroError({
...AstroErrorData.UnavailableAstroGlobal,
message: AstroErrorData.UnavailableAstroGlobal.message(name),
});
}
// This is used to create the top-level Astro global; the one that you can use
// inside of getStaticPaths. See the `astroGlobalArgs` option for parameter type.
export function createAstro(site: string | undefined): AstroGlobal {
return {
// TODO: throw in Astro 8
get site() {
// This is created inside of the runtime so we don't have access to the Astro logger.
console.warn(
`Astro.site inside getStaticPaths is deprecated and will be removed in a future major version of Astro. Use import.meta.env.SITE instead`,
);
return site ? new URL(site) : undefined;
},
// TODO: throw in Astro 8
get generator() {
// This is created inside of the runtime so we don't have access to the Astro logger.
console.warn(
`Astro.generator inside getStaticPaths is deprecated and will be removed in a future major version of Astro.`,
);
return ASTRO_GENERATOR;
},
get callAction(): any {
throw createError('callAction');
},
get clientAddress(): any {
throw createError('clientAddress');
},View on GitHub (pinned to 3578d45d34)
Solutions
- Replace Astro.site with import.meta.env.SITE inside getStaticPaths, wrapping it in new URL(...) if you need a URL object
- Make sure `site` is set in astro.config.mjs, otherwise import.meta.env.SITE is undefined
- Move any other Astro-global reads (params/props/generator) out of getStaticPaths into the page component where the real Astro global exists
Example fix
// before
export async function getStaticPaths() {
const site = Astro.site; // deprecation warning on every build
return posts.map((p) => ({
params: { slug: p.slug },
props: { url: new URL(`/posts/${p.slug}`, site) },
}));
}
// after
export async function getStaticPaths() {
const site = new URL(import.meta.env.SITE);
return posts.map((p) => ({
params: { slug: p.slug },
props: { url: new URL(`/posts/${p.slug}`, site) },
}));
} Defensive patterns
Strategy: validation
Validate before calling
// Helper used everywhere instead of the deprecated global — throws early if site is unset
export function getSite(): URL {
const site = import.meta.env.SITE;
if (!site) throw new Error('Set `site` in astro.config.mjs so import.meta.env.SITE is defined');
return new URL(site);
}
// inside getStaticPaths:
const site = getSite(); Prevention
- Grep the repo for `Astro.` reads inside getStaticPaths blocks and migrate them to import.meta.env.SITE / ASTRO_VERSION
- Centralize site access in one getSite() helper so a future API change touches one file
- Treat deprecation console.warn output as a CI failure before major Astro upgrades
When it happens
Trigger: Calling `Astro.site` inside an exported getStaticPaths() function — in .astro pages, endpoints, or integration-injected routes — during `astro dev` or `astro build`. Each property read fires the warning once (it is an inline console.warn in the getter, not a logged-once guard).
Common situations: Generating sitemap entries, canonical URLs, OG tags, or absolute links from the configured site inside getStaticPaths. Typically surfaces after upgrading to an Astro version that introduced this deprecation ahead of the Astro 7 removal, when CI or dev suddenly shows the warning on every build.
Understand the failure class
Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.
Related errors
- Astro.generator inside getStaticPaths is deprecated and will
- GetStaticPathsRequired
- InvalidGetStaticPathsReturn
- InvalidGetStaticPathsEntry
- GetStaticPathsExpectedParams
AI-assisted analysis of withastro/astro@3578d45d34 (2026-08-21).
Data as JSON: /api/errors/8ca16b84d58fb0b8.
Report an issue: GitHub.