vercel/next.js · error

Middleware is not supported in minimal mode. Please remove t

Error message

Middleware is not supported in minimal mode. Please remove the `NEXT_MINIMAL` environment variable.

What it means

Thrown at the start of NextNodeServer.runEdgeFunction() when process.env.NEXT_MINIMAL is set. Minimal mode is a trimmed runtime (used by certain serverless/edge deployments) that intentionally excludes middleware and edge-function support, so invoking an edge function in that mode is rejected.

Source

Thrown at packages/next/src/server/next-server.ts:2027

        'clonableBody',
        getCloneableBody(req.originalRequest, bodySizeLimit)
      )
    }
  }

  protected async runEdgeFunction(params: {
    req: NodeNextRequest
    res: NodeNextResponse
    query: ParsedUrlQuery
    params: Params | undefined
    page: string
    appPaths: string[] | null
    match?: RouteMatch
    onError?: (err: unknown) => void
    onWarning?: (warning: Error) => void
  }): Promise<FetchEventResult | null> {
    if (process.env.NEXT_MINIMAL) {
      throw new Error(
        'Middleware is not supported in minimal mode. Please remove the `NEXT_MINIMAL` environment variable.'
      )
    }
    let edgeInfo: ReturnType<typeof this.getEdgeFunctionInfo> | undefined

    const { query, page, match } = params

    if (!match)
      await this.ensureEdgeFunction({
        page,
        appPaths: params.appPaths,
        url: params.req.url,
      })
    edgeInfo = this.getEdgeFunctionInfo({
      page,
      middleware: false,
    })

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Unset the NEXT_MINIMAL environment variable when you need middleware/edge functions (remove it from your env/Dockerfile/serverless config).
  2. If you intentionally run in minimal mode, remove middleware.ts and any edge runtime route handlers.
  3. Confirm the deployment target actually requires minimal mode; standard `next start` does not.

Example fix

// before
NEXT_MINIMAL=1 next start
// after
next start
Defensive patterns

Strategy: validation

Validate before calling

if (process.env.NEXT_MINIMAL && hasMiddleware) {
  console.warn('NEXT_MINIMAL is set but middleware exists; unsetting NEXT_MINIMAL.')
  delete process.env.NEXT_MINIMAL
}

Prevention

When it happens

Trigger: The NEXT_MINIMAL environment variable is truthy (set to any value) and a request hits a route handled by middleware or an edge runtime function. runEdgeFunction checks `if (process.env.NEXT_MINIMAL)` and throws before doing any work.

Common situations: A serverless/edge platform sets NEXT_MINIMAL by default and the app adds middleware.ts; leftover NEXT_MINIMAL=1 from a previous deployment config copied into a standard Node server; testing a minimal bundle locally while middleware is present.

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/001d8147ba1d7014. Report an issue: GitHub.