Should Nuxt 3 fall back to a last-known-good module schema when validation fails after an update?
0 reputation · 26 Aug 2024, 08:34 UTC
0 reputation · 26 Aug 2024, 08:34 UTC
Nuxt 3 lets module authors declare configuration schemas via @nuxt/schema (using Zod or JSON Schema), and the app validates that configuration at boot. When validation fails, startup aborts with a validation error — there is no built-in mechanism to revert to a previously valid schema state.
This makes any module schema change effectively a breaking change: the developer must manually fix the configuration before the app can start again. In a production or CI context, a failed deploy caused by a schema mismatch means downtime until someone intervenes, since Nuxt neither migrates old config shapes nor rolls back to a prior schema version.
Assume Nuxt 3.x with a module using @nuxt/schema for typed configuration.
Is there any supported or planned mechanism in Nuxt for schema migrations or safe fallback to a last-known-good configuration when validation fails? If not, what is the recommended pattern for module authors to version their schemas so an update does not hard-block application startup? Does the community treat this strictly as the module author's responsibility, or is it considered a gap in the framework?
31275 reputation · 26 Aug 2024, 13:03 UTC
Short answer: No. Nuxt 3 has no supported or announced mechanism for schema migrations or automatic fallback to a last-known-good configuration when @nuxt/schema validation fails at boot. Startup aborting with a validation error is deliberate fail-fast behavior, and the ecosystem treats config compatibility as the module author's responsibility, not a framework gap.
The likely explanation is architectural: @nuxt/schema exists to type and validate nuxt.config at build/setup time. It is not a runtime state store, so Nuxt never persists a "previously valid" configuration anywhere. A rollback feature would require the framework to snapshot every config that ever validated successfully, decide which snapshot counts as "good," and silently boot with it — which would mask breaking changes and produce far harder-to-debug behavior than a clear startup error. Fail-fast is the standard choice for build-time config across frameworks for exactly this reason.
One caveat: exact validator behavior (Zod, Standard Schema-compatible validators, or older untyped/jiti-style inference) varies across Nuxt 3.x minor releases. Confirm what's pinned in your project before assuming specifics:
npm ls @nuxt/schema
# or inspect the installed package directly
cat node_modules/@nuxt/schema/package.json | head -20The community convention is that modules absorb their own breaking changes. Concretely:
.catch(), .preprocess(), or .transform() to map legacy option shapes onto the new schema instead of failing validation.consola rather than throwing.You can wrap your own option parsing in try/catch inside the module's setup hook and degrade gracefully, but doing this around framework validation hides genuine misconfiguration — use it only for options you fully own, not as a blanket fallback.
For the production/CI downtime concern, the guard is pipeline-side, not runtime rollback. Schema validation runs during nuxi prepare and nuxi build, so a mismatch should fail the build long before anything ships:
# In CI, before deploy:
npx nuxi buildIf the build passes, the config validated. If a module update changes its schema, the pipeline fails with the validation error and the previous deployment keeps running — which is the "last-known-good" behavior you want, just enforced at the right layer.
nuxi build to observe the exact failure mode in your version — timing differs between dev and build, and some errors only surface during module setup.Bottom line: don't wait for a framework fallback — write lenient, additive schemas with transforms and warnings, and let CI be your rollback boundary.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.