{"record":{"id":"ad6ca0a4e3d147d2","repo":"vercel/next.js","slug":"api-route-returned-a-response-object-in-the-node-j","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/api-utils/node/api-resolver.ts","lineNumber":441,"sourceCode":"      opts?: {\n        unstable_onlyGenerated?: boolean\n      }\n    ) => revalidate(urlPath, opts || {}, req, apiContext)\n\n    const resolver = interopDefault(resolverModule)\n    let wasPiped = false\n\n    if (process.env.NODE_ENV !== 'production') {\n      // listen for pipe event and don't show resolve warning\n      res.once('pipe', () => (wasPiped = true))\n    }\n\n    const apiRouteResult = await resolver(req, res)\n\n    if (process.env.NODE_ENV !== 'production') {\n      if (typeof apiRouteResult !== 'undefined') {\n        if (apiRouteResult instanceof Response) {\n          throw new Error(\n            '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'\n          )\n        }\n        console.warn(\n          `API handler should not return a value, received ${typeof apiRouteResult}.`\n        )\n      }\n\n      if (!externalResolver && !isResSent(res) && !wasPiped) {\n        console.warn(\n          `API resolved without sending a response for ${req.url}, this may result in stalled requests.`\n        )\n      }\n    }\n  } catch (err) {\n    await onError?.(\n      err,\n      {","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/api-utils/node/api-resolver.ts#L423-L459","documentation":"Thrown by apiResolver() in development when a Pages Router API route (Node.js runtime) returns a Response object from its handler. The Node.js runtime for API routes does not support the web Response type; only the Edge runtime does. This is a dev-only guard (NODE_ENV !== 'production') to catch the mistake early.","triggerScenarios":"An API route file under pages/api/ without `export const config = { runtime: 'edge' }` returns `new Response(...)` or `Response.json(...)` from its handler. At line 440 the result is checked `instanceof Response` and the error is thrown.","commonSituations":"Copying an Edge API route snippet into a Node API route; using fetch-like patterns that return Response; upgrading code that assumed web Response works in Node runtime.","solutions":["Add `export const config = { runtime: 'edge' }` to the API route to switch to the Edge runtime.","Or refactor the handler to use res.status().json()/res.send() instead of returning a Response.","Move the logic into an App Router route handler (app/api/route.ts) which supports Response natively."],"exampleFix":"// before (pages/api/edge-only.ts) - Node runtime returning Response\nexport default function handler(req, res) {\n  return Response.json({ ok: true }) // throws in dev\n}\n// after - declare edge runtime\nexport const config = { runtime: 'edge' }\nexport default function handler(req, res) {\n  return Response.json({ ok: true })\n}","handlingStrategy":"validation","validationCode":"// Ensure the route declares the correct runtime before returning Response\nfunction assertEdgeRuntime(config: { runtime?: string } | undefined) {\n  if (config?.runtime !== 'edge') throw new Error('Response requires runtime: edge')\n}","typeGuard":"function isEdgeRoute(config: any): boolean {\n  return config?.config?.runtime === 'edge'\n}","tryCatchPattern":null,"preventionTips":["Add `export const config = { runtime: 'edge' }` to API routes that return Response.","Prefer App Router route handlers for Response-based APIs.","Run the dev server locally to catch this guard before deploy."],"tags":["api-routes","edge-runtime","node-runtime","development"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}