Nuxt 3's existing $schema
unifies core configuration types and documentation. However, it only supports JSON schema, and is primarily intended for module authors.
There is no built-in support for 'Standard Schema' (Zod, Valibot, ArkType, etc.) to validate the options. This RFC therefore proposes extending the $schema
(and module hooks) to accept standard schema objects and merge them into the global configuration schema. This would enable partial build-time validation.
For reference, see:
$schema
to be a Standard Schema
In nuxt.config.ts
, if $schema
is a Zod/Valibot object, Nuxt will:
isStandardSchema
check).import { object, string } from 'valibot' export default defineNuxtConfig({ runtimeConfig: { baseApi: 'https://api.com', token: 12345 // ❌ fails validation, }, $schema: object({ runtimeConfig: object({ baseApi: string(), token: string() }) }) })
Here only runtimeConfig.baseApi
and runtimeConfig.token
are validated.
schema:extend
with $standardSchema
In a Nuxt module, hook into schema:extend and push:
nuxt.hook('schema:extend', (schemas) => { schemas.push({ myModule: { $standardSchema: z.object({ endpoint: z.string().url(), timeout: z.number().int().positive().optional() }) } }) })
At build time, Nuxt converts that Standard schema → JSON Schema under config.myModule
and merges/validates accordingly.
z.object(...).strict()
), Nuxt will error on extra keys within that subtree only.During nuxi dev/build/generate
, run merged JSON Schema validation against nuxt.options
.
If errors occur, abort and log:
❌ [Nuxt Schema] Validation failed at "runtimeConfig.token":
Expected string, received number (12345)
More Examples Module‐Level Schema
// modules/nuxt-my-feature/module.ts import { defineNuxtModule } from '@nuxt/kit' import { z } from 'zod' export default defineNuxtModule({ meta: { name: 'nuxt-my-feature' }, setup(_, nuxt) { nuxt.hook('schema:extend', (schemas) => { schemas.push({ myFeature: { $standardSchema: z.object({ endpoint: z.string().url(), timeout: z.number().positive().optional() }) } }) }) } })
If a user sets:
export default defineNuxtConfig({ modules: ['nuxt-my-feature'], myFeature: { endpoint: 'not-a-url', // ❌ fails timeout: 5000 // ✅ okay } })
Nuxt will error on myFeature.endpoint
.
// nuxt.config.ts import { object, string } from 'valibot' export default defineNuxtConfig({ runtimeConfig: { baseApi: 42, // ❌ fails: expects string token: 'abc123', // ✅ okay extra: true // ✅ allowed (ignored) }, $schema: object({ runtimeConfig: object({ baseApi: string(), token: string() }) }) }) Build aborts with: ❌ [Nuxt Schema] Validation failed at "runtimeConfig.baseApi": Expected string, received number (42)Conclusion
By accepting Standard Schema in $schema
and in module hooks ($standardSchema
), Nuxt can:
I would love to collaborate on implementing this feature (from schema‐detection to merge/validation).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4