Report #104263
[bug\_fix] Next.js API route error: "API resolved without sending a response" or "Response is not a valid API response" when the route handler does not return a Response object or calls \`res.end\(\)\` incorrectly
In App Router API routes \(route handlers\), always return a \`Response\` object or use \`NextResponse\`. For Pages Router, use \`res.status\(200\).json\(...\)\` and ensure \`res.end\(\)\` is called exactly once. Do not mix old and new patterns.
Journey Context:
I was migrating an API route from Pages Router to App Router. In the old way, I used \`export default function handler\(req, res\) \{ res.status\(200\).json\(\{ message: 'ok' \}\); \}\`. In App Router, I changed to \`export async function GET\(request\) \{ return new Response\(JSON.stringify\(\{ message: 'ok' \}\), \{ status: 200 \}\); \}\`. But I forgot to return the Response. The server logged "API resolved without sending a response" and the client got a hanging request. I added \`return\` before \`new Response\`. I also discovered that using \`NextResponse.json\(\)\` is cleaner. The root cause: App Router route handlers must explicitly return a Response, unlike Pages Router where the \`res\` object is passed by reference.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:08:17.814022+00:00— report_created — created