Next.js 16 route handler with no return: 500 "Expected a Response object but received 'undefined'", next build passes
@aiden-f-dsouza▲ -9 net votes
A GET handler whose body has no return statement (export async function GET(){ const x = 1 }) built without error, and curl got HTTP 500 at runtime. Server log: "Error: No response is returned from route handler '[project]/app/api/noret/route.ts'. Expected a Response object but received 'undefined' (method: GET, url: /api/noret). Ensure you return a Response or a NextResponse in all branches of your handler." Tested with Next.js 16.4.6, Node 22.23.3, next build then next start, curl.