vercel/next.js · error

Statically exporting a Next.js application via `next export`

Error message

Statically exporting a Next.js application via `next export` disables API routes and middleware.
This command is meant for static-only hosts, and is not necessary to make your application static.
Pages in your application without server-side data dependencies will be automatically statically exported by `next build`, including pages powered by `getStaticProps`.
Learn more: https://nextjs.org/docs/messages/api-routes-static-export

What it means

Error "Statically exporting a Next.js application via `next export` disables API routes and middleware. This command is meant for static-only hosts, and is not necessary to make your application static. Pages in your application without server-side data dependencies will be automatically statically exported by `next build`, including pages powered by `getStaticProps`. Learn more: https://nextjs.org/docs/messages/api-routes-static-export" thrown in vercel/next.js.

Source

Thrown at packages/next/src/export/index.ts:649

  if (!options.buildExport) {
    try {
      const middlewareManifest = require(
        join(distDir, SERVER_DIRECTORY, MIDDLEWARE_MANIFEST)
      ) as MiddlewareManifest

      const functionsConfigManifest = require(
        join(distDir, SERVER_DIRECTORY, FUNCTIONS_CONFIG_MANIFEST)
      )

      hasMiddleware =
        Object.keys(middlewareManifest.middleware).length > 0 ||
        Boolean(functionsConfigManifest.functions?.['/_middleware'])
    } catch {}

    // Warn if the user defines a path for an API page
    if (hasApiRoutes || hasMiddleware) {
      if (nextConfig.output === 'export') {
        Log.warn(
          yellow(
            `Statically exporting a Next.js application via \`next export\` disables API routes and middleware.`
          ) +
            `\n` +
            yellow(
              `This command is meant for static-only hosts, and is` +
                ' ' +
                bold(`not necessary to make your application static.`)
            ) +
            `\n` +
            yellow(
              `Pages in your application without server-side data dependencies will be automatically statically exported by \`next build\`, including pages powered by \`getStaticProps\`.`
            ) +
            `\n` +
            yellow(
              `Learn more: https://nextjs.org/docs/messages/api-routes-static-export`
            )
        )

View on GitHub (pinned to 258b1c1bc0)

Solutions

  1. Use `next build` with static optimization instead of `next export`; API routes and middleware are not available in static exports.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/next/src/export/index.ts:638 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of vercel/next.js@258b1c1bc0 (2026-08-19). Data as JSON: /api/errors/1ea10f966a197fbb. Report an issue: GitHub.