I am developing a tiny REST API for a Next.js app. If I place my route.ts in rootDir -> app -> api -> hello -> route.ts that looks like this, then it works:
//route.ts
export async function GET(request: Request) {
return new Response('Hello, Next.js!')
}
I can make a successful GET request via Postman to localhost:3000/api/hello.
I change the code now to the following:
import { NextApiRequest, NextApiResponse } from "next";
export async function GET(request: NextApiRequest, response: NextApiResponse) {
return response.json({ message: "Hello, Next.js!" });
}
Now it fails and I get the error message:
error TypeError: response.json is not a function
The issue is known but the upgrade to the latest lts or the latest node version does not fix my problem: https://github.com/vercel/next.js/issues/48524.