nuxt-safe-runtime-config
Nuxt Safe Runtime Config
Deprecated. Nuxt 4.7 checks runtimeConfig schemas itself.
This module is deprecated. Nuxt 4.7 accepts a Standard JSON Schema (Zod 4.2+, ArkType 2.1.28+, or Valibot wrapped in toStandardJsonSchema()) in runtimeConfig, converts NUXT_* strings to its types, refuses to start on a missing or mistyped value, and types useRuntimeConfig(). Move your schema there with one command:
npx nuxt-safe-runtime-config@latest migrate --dry-run # print the changes and the report, write nothing
npx nuxt-safe-runtime-config@latest migrate # apply themPass a directory when the app isn't in the current one: npx nuxt-safe-runtime-config@latest migrate apps/web. The codemod needs Nuxt 4.7 or later. If you use Zod or ArkType, upgrade to Zod 4.2 or ArkType 2.1.28 first.
The migration guide covers what the codemod changes, when it stops, and what Nuxt doesn't check:
- Nuxt doesn't run URL formats, minimums and maximums, patterns or
.refine(). The codemod lists each one in its report. - A schema in
nuxt.config.tsalways stops the server on a bad value.onError: 'warn' | 'ignore'has no equivalent. - Apps that use
envSchemamove to ViteHub Env on Nuxt 5. Nitro apps without Nuxt move to ViteHub Env on Nitro 3. Apps whose schema has transforms can pinnuxt-safe-runtime-config@0.5.0, which keeps working.
Maintenance
The repository and the docs site stay online in maintenance mode:
- Security fixes and severe bugs only. No new features.
- Report a vulnerability privately on GitHub. Don't open a public issue for it.
Reference
For apps that still run the module. The old guides describe it in full.
// nuxt.config.ts
import * as v from 'valibot'
export default defineNuxtConfig({
modules: ['nuxt-safe-runtime-config'],
runtimeConfig: {
databaseUrl: '',
public: { apiBase: 'https://api.example.com' },
},
safeRuntimeConfig: {
$schema: v.object({
databaseUrl: v.pipe(v.string(), v.url()),
public: v.object({ apiBase: v.pipe(v.string(), v.url()) }),
}),
},
})The module checks the schema during nuxt build and again when the server starts, after NUXT_* overrides. useSafeRuntimeConfig() returns the values typed from the schema; pass event in server handlers. Configuration lists every option.
Contribution
Local development
# Install dependencies
pnpm install
# Generate type stubs
pnpm run dev:prepare
# Develop with the playground
pnpm run dev
# Build the playground
pnpm run dev:build
# Run ESLint
pnpm run lint
# Run Vitest
pnpm run test
pnpm run test:watchReleases go through uppt. Every push to main updates a draft release/vX.Y.Z PR built from conventional commits. Merging it tags the version, creates the GitHub release, and publishes the package to npm through OIDC trusted publishing. If publishing fails after the tag exists, run gh workflow run release.yml --ref vX.Y.Z.