Configuration
All options for safeRuntimeConfig in your nuxt.config.ts.
Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
$schema | StandardSchemaV1 | - | Your validation schema (required) |
validateAtBuild | boolean | true | Validate during dev/build |
validateAtRuntime | boolean | false | Validate when server starts |
onError | 'throw' | 'warn' | 'ignore' | 'throw' | Validation error behavior |
jsonSchemaTarget | string | 'draft-2020-12' | JSON Schema version for runtime |
Example Configuration
export default defineNuxtConfig({
safeRuntimeConfig: {
$schema: runtimeConfigSchema,
// Validation timing
validateAtBuild: true, // default
validateAtRuntime: false, // opt-in
// Error handling
onError: 'throw', // 'throw' | 'warn' | 'ignore'
// JSON Schema
jsonSchemaTarget: 'draft-2020-12',
},
})
Error Behaviors
'throw' (default)
Stops the build or throws an error at runtime. Recommended for catching issues early.
'warn'
Logs a warning but continues. Useful during migration or when some values are expected to be missing in development.
'ignore'
Silently continues. Use sparingly.
JSON Schema Target
The jsonSchemaTarget option controls which JSON Schema draft to use for runtime validation. Options:
'draft-2020-12'(default) - latest, best compatibility'draft-2019-09'- if your tools require it'draft-07'- legacy support
Runtime validation uses @cfworker/json-schema, a lightweight (~8KB) validator that works on all runtimes including edge.
When a schema library does not expose native JSON Schema output, the module falls back to @standard-community/standard-json. Valibot and Zod converter dependencies are bundled with the module package, so application projects do not need extra installs for those libraries.
Getting Started
Validate your Nuxt runtime config at build or runtime using Zod, Valibot, ArkType, or any Standard Schema compatible library.
Type Safety
The module generates TypeScript types from your schema, making useSafeRuntimeConfig() fully typed without manual generics in both app and server code.