feat: print a more helpful error message for output: hybrid (#14958)

* feat: print a more helpful error message for `output: hybrid`

* Add type predicate
This commit is contained in:
Matt Kane
2025-12-04 12:02:43 +00:00
committed by GitHub
parent 45c9accf3c
commit 70eb542f3b
3 changed files with 22 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
---
'astro': minor
---
Gives a helpful error message if a user sets `output: "hybrid"` in their Astro config.
The option was removed in Astro 5, but lots of content online still references it, and LLMs often suggest it. It's not always clear that the replacement is `output: "static"`, rather than `output: "server"`. This change adds a helpful error message to guide humans and robots.

View File

@@ -149,9 +149,13 @@ export const AstroConfigSchema = z.object({
.optional()
.default(ASTRO_CONFIG_DEFAULTS.trailingSlash),
output: z
.union([z.literal('static'), z.literal('server')])
.union([z.literal('static'), z.literal('server'), z.literal('hybrid')])
.optional()
.default('static'),
.default('static')
.refine((val): val is 'static' | 'server' => val !== 'hybrid', {
message:
'The `output: "hybrid"` option has been removed. Use `output: "static"` (the default) instead, which now behaves the same way.',
}),
scopedStyleStrategy: z
.union([z.literal('where'), z.literal('class'), z.literal('attribute')])
.optional()

View File

@@ -90,6 +90,15 @@ describe('Config Validation', () => {
);
});
it('errors with helpful message when output is "hybrid"', async () => {
const configError = await validateConfig({ output: 'hybrid' }).catch((err) => err);
assert.equal(configError instanceof z.ZodError, true);
assert.ok(
configError.errors[0].message.includes('removed'),
'Error message should explain that "hybrid" has been removed',
);
});
describe('i18n', async () => {
it('defaultLocale is not in locales', async () => {
const configError = await validateConfig({