vercel/next.js · error · Error
Draft mode cannot be disabled during build-time instant vali
Error message
Draft mode cannot be disabled during build-time instant validation.
What it means
The companion to error 151: the instant-validation DraftModeProvider.disable() stub throws because disabling draft mode is meaningless during build-time validation (draft mode is never enabled there). Any call to draftMode().disable() in code exercised by instant validation triggers it.
Source
Thrown at packages/next/src/server/app-render/instant-validation/instant-samples.ts:244
/**
* Creates a DraftModeProvider that always returns isEnabled: false.
*/
export function createDraftModeForValidation(): DraftModeProvider {
// Create a minimal DraftModeProvider-compatible object
// that always reports draft mode as disabled.
//
// private properties that can't be set from outside the class.
return {
get isEnabled() {
return false
},
enable() {
throw new Error(
'Draft mode cannot be enabled during build-time instant validation.'
)
},
disable() {
throw new Error(
'Draft mode cannot be disabled during build-time instant validation.'
)
},
} as Partial<DraftModeProvider> as DraftModeProvider
}
/**
* Creates params wrapped with an exhaustive proxy.
* Accessing a param not declared in the sample will throw an error.
*/
export function createExhaustiveParamsProxy<TParams extends Params>(
underlyingParams: TParams,
declaredParamNames: Set<string>,
route: string
): TParams {
return new Proxy(underlyingParams, {
get(target, prop, receiver) {
if (View on GitHub (pinned to 0ae8c72462)
Solutions
- Guard draftMode().disable() so it does not run during build/validation.
- Place draft-mode disable logic in a runtime-only route handler excluded from validation.
- Condition the call on a real request context (e.g. presence of a query param).
- Ensure the disable path is not reachable from statically-validated routes.
Example fix
// before
// export default function Handler() { draftMode().disable() }
// after
// if (process.env.NEXT_RUNTIME) draftMode().disable() Defensive patterns
Strategy: validation
Validate before calling
// Skip draft-mode disablement during build/validation.
function disablePreview() {
if (process.env.NEXT_PHASE === 'phase-production-build') return
draftMode().disable()
} Prevention
- Keep draftMode().disable() in runtime-only route handlers.
- Exclude preview-exit routes from instant validation samples.
- Guard draft-mode calls with a runtime/phase check.
- Avoid calling draft APIs from statically validated components.
When it happens
Trigger: During instant validation, application code calls draftMode().disable(). The validation provider's disable() throws.
Common situations: A 'disable preview' route handler or a component that clears draft mode is run during validation; shared cleanup code unconditionally disables draft mode; preview-exit logic invoked at build time.
Related errors
- Draft mode cannot be enabled during build-time instant valid
- Invalid sample: Defining cookies via a "cookie" header is no
- Expected sample param value for segment '${rawSegment}' to b
- Expected sample param value for segment '${rawSegment}' to b
- Invalid --top value: ${topRaw}
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/c1676227d8ef7f8e.
Report an issue: GitHub.