vercel/next.js · error · Error

Route ${workStore.route} used `connection()` inside `generat

Error message

Route ${workStore.route} used `connection()` inside `generateStaticParams`. This is not supported because `generateStaticParams` runs at build time without an HTTP request. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context

What it means

Error "Route ${workStore.route} used `connection()` inside `generateStaticParams`. This is not supported because `generateStaticParams` runs at build time without an HTTP request. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context" thrown in vercel/next.js.

Source

Thrown at packages/next/src/server/request/connection.ts:76

          Error.captureStackTrace(error, connection)
          applyOwnerStack(error)
          workStore.invalidDynamicUsageError ??= error
          throw error
        }
        case 'private-cache': {
          // It might not be intuitive to throw for private caches as well, but
          // we don't consider runtime prefetches as "actual requests" (in the
          // navigation sense), despite allowing them to read cookies.
          const error = createConnectionInPrivateUseCacheError(workStore.route)
          Error.captureStackTrace(error, connection)
          applyOwnerStack(error)
          workStore.invalidDynamicUsageError ??= error
          throw error
        }
        case 'unstable-cache':
          throw createConnectionInUnstableCacheError(workStore.route)
        case 'generate-static-params':
          throw new Error(
            `Route ${workStore.route} used \`connection()\` inside \`generateStaticParams\`. This is not supported because \`generateStaticParams\` runs at build time without an HTTP request. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context`
          )
        case 'prerender':
        case 'prerender-client':
        case 'prerender-runtime':
          // We return a promise that never resolves to allow the prerender to
          // stall at this point.
          return makeDynamicHangingPromise(
            workUnitStore.renderSignal,
            workStore.route,
            '`connection()`'
          )
        case 'validation-client': {
          // TODO(NAR-789): make this consistent with the actual browser behavior when we change it.
          // Until then, erroring is fine.
          const exportName = '`connection`'
          throw new InvariantError(
            `${exportName} must not be used within a Client Component. Next.js should be preventing ${exportName} from being included in Client Components statically, but did not in this case.`

View on GitHub (pinned to 258b1c1bc0)

Solutions

  1. Do not call connection() inside generateStaticParams; it runs at build time without a request.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: connection() is called inside generateStaticParams.

Common situations: Using the connection() dynamic API at build time inside generateStaticParams.


AI-assisted analysis of vercel/next.js@258b1c1bc0 (2026-09-01). Data as JSON: /api/errors/0201926fe189fd8d. Report an issue: GitHub.