nuxt-safe-runtime-config
nuxt-safe-runtime-config

Validate runtime config with Standard Schema at build or runtime, with optional Shelve secrets integration.

Nuxt Safe Runtime Config

Deprecated. Nuxt 4.7 checks runtimeConfig schemas itself.

Migration guide

npm versionnpm downloadsLicense

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 them

Pass 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.ts always stops the server on a bad value. onError: 'warn' | 'ignore' has no equivalent.
  • Apps that use envSchema move to ViteHub Env on Nuxt 5. Nitro apps without Nuxt move to ViteHub Env on Nitro 3. Apps whose schema has transforms can pin nuxt-safe-runtime-config@0.5.0, which keeps working.

Maintenance

The repository and the docs site stay online in maintenance mode:

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:watch

Releases 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.