vercel/next.js · error

API handler should not return a value, received ${typeof api

Error message

API handler should not return a value, received ${typeof apiRouteResult}.

What it means

apiResolver warns (dev only) when an API route handler returns a non-undefined value; API routes must communicate via the res object, so a return value signals a misunderstanding (returning a Response throws outright in the Node runtime) and the value is otherwise ignored.

Source

Thrown at packages/next/src/server/api-utils/node/api-resolver.ts:445

    const resolver = interopDefault(resolverModule)
    let wasPiped = false

    if (process.env.NODE_ENV !== 'production') {
      // listen for pipe event and don't show resolve warning
      res.once('pipe', () => (wasPiped = true))
    }

    const apiRouteResult = await resolver(req, res)

    if (process.env.NODE_ENV !== 'production') {
      if (typeof apiRouteResult !== 'undefined') {
        if (apiRouteResult instanceof Response) {
          throw new Error(
            'API route returned a Response object in the Node.js runtime, this is not supported. Please use `runtime: "edge"` instead: https://nextjs.org/docs/api-routes/edge-api-routes'
          )
        }
        console.warn(
          `API handler should not return a value, received ${typeof apiRouteResult}.`
        )
      }

      if (!externalResolver && !isResSent(res) && !wasPiped) {
        console.warn(
          `API resolved without sending a response for ${req.url}, this may result in stalled requests.`
        )
      }
    }
  } catch (err) {
    await onError?.(
      err,
      {
        method: req.method || 'GET',
        headers: req.headers,
        path: req.url || '/',
      },

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Do not return a value from the API handler; end the response with `res.status(...).json(...)` or `res.end()`.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/next/src/server/api-utils/node/api-resolver.ts:445 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19). Data as JSON: /api/errors/e3ea4a9e25804ae2. Report an issue: GitHub.