Response.json is not a function
Unanswered
Dutch posted this in #help-forum
DutchOP
I have a NextJS 14.2.3 project, and recently I have been getting errors like the below when using route handlers to return some JSON data.
Annoyingly, it doesn't not seem to happen every time I spin a dev or production server up, but if the first API response returns this error then they all do.
At the moment the only way I can seem to get it back is a combination of deleting the .next folder, or deleting the node modules folder, and restarting the dev server or rebuilding prod, but neither seems to work consistency so I have no idea if this is actually helping.
Has anyone else seen anything similar?
TypeError: Response.json is not a function at u.json (/home/ubuntu/vertase/dev/.next/server/chunks/9466.js:12:6870) at g (/home/ubuntu/vertase/dev/.next/server/app/api/(admin)/hauliers/route.js:1:2608) at process.processTicksAndRejections (node:internal/process/task\_queues:95:5) at async /home/ubuntu/vertase/dev/node\_modules/.pnpm/next@[14.2.4\_react-dom@18.3.1\_reac](mailto:14.2.4_react-dom@18.3.1_reac) t@18.3.1\_\_react@18.3.1/node\_modules/next/dist/compiled/next-server/app-route.runtime.prod. js:6:36258 at async eR.execute (/home/ubuntu/vertase/dev/node\_modules/.pnpm/next@14.2.4\_react-dom .3.1\_react@18.3.1\_\_react@18.3.1/node\_modules/next/dist/compiled/next-server/app-route.r untime.prod.js:6:26874) at async eR.handle (/home/ubuntu/vertase/dev/node\_modules/.pnpm/next@14.2.4\_react-dom@ 18.3.1\_react@18.3.1\_\_react@18.3.1/node\_modules/next/dist/compiled/next-server/app-route.ru ntime.prod.js:6:37512) at async doRender Annoyingly, it doesn't not seem to happen every time I spin a dev or production server up, but if the first API response returns this error then they all do.
At the moment the only way I can seem to get it back is a combination of deleting the .next folder, or deleting the node modules folder, and restarting the dev server or rebuilding prod, but neither seems to work consistency so I have no idea if this is actually helping.
Has anyone else seen anything similar?
5 Replies
@Dutch share your code snipet that's helpful
DutchOP
It could be any route handler, even one as basic as this has the issue once it starts...
'''
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
return NextResponse.json({ success: true });
}
'''
Restarting the dev anywhere between 1-3 times seems to bring it back.
I have spotted that if there is an error fetching data in one of the api routes that's fetching data via drizzle (normally due to too many connections), that when I restart dev the issue is there until I restart a few times
'''
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
return NextResponse.json({ success: true });
}
'''
Restarting the dev anywhere between 1-3 times seems to bring it back.
I have spotted that if there is an error fetching data in one of the api routes that's fetching data via drizzle (normally due to too many connections), that when I restart dev the issue is there until I restart a few times
can you try
return Response.json({data});DutchOP
I have tried this as well, same issue...
It seems to follow this annoying pattern...
- Need to restart server for some reason,
- API routes all return this message,
- Stop Dev server and restart,
- API routes OK, until I next need to restart
- Need to restart server for some reason,
- API routes all return this message,
- Stop Dev server and restart,
- API routes OK, until I next need to restart