TypeError: Response body object should not be disturbed or locked #49524
Replies: 31 comments 21 replies
-
Hi ! Any idea please ? |
Beta Was this translation helpful? Give feedback.
-
I suggest reporting this as an issue |
Beta Was this translation helpful? Give feedback.
-
Facing same issue around here in my React/Typescript/Prisma app...
|
Beta Was this translation helpful? Give feedback.
-
I have created an Issue, here it is |
Beta Was this translation helpful? Give feedback.
-
I think the issue is not related to Firebase, I'm experiencing this with Call stack: - error TypeError: Response body object should not be disturbed or locked
at extractBody (node:internal/deps/undici/undici:6384:17)
at new Request (node:internal/deps/undici/undici:7264:48)
at new NextRequest
at NextRequestAdapter.fromNodeNextRequest
at NextRequestAdapter.fromBaseNextRequest
at RouteHandlerManager.handle
at process.processTicksAndRejections
at async doRender
at async cacheEntry.responseCache.get.incrementalCache.incrementalCache |
Beta Was this translation helpful? Give feedback.
-
I agree, it's nothing to do with Firebase. I just started a REST API fresh with , got as far as DELETE and the same thing happens. The function is quite literally empty.
export async function DELETE(request: Request) {
} "dependencies": {
"@prisma/client": "^4.15.0",
"@types/node": "20.2.5",
"@types/react": "18.2.9",
"@types/react-dom": "18.2.4",
"@types/validator": "^13.7.17",
"autoprefixer": "10.4.14",
"eslint": "8.42.0",
"next": "13.4.4",
"postcss": "8.4.24",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-validator": "^0.1.0",
"tailwindcss": "3.3.2",
"typescript": "5.1.3",
"validator": "^13.9.0"
},
"devDependencies": {
"eslint-config-next": "^13.4.4",
"prisma": "^4.15.0"
} |
Beta Was this translation helpful? Give feedback.
-
Raised it myself: #51439 |
Beta Was this translation helpful? Give feedback.
-
I have the same problem and tested earlier next versions. Version 13.2.5-canary.28 has a fix called "Fix dev ipc request on node v16" #47825.
Since the error messages of this current problem mentions 'undici' and was working before maybe somewhere there is the cause? |
Beta Was this translation helpful? Give feedback.
-
Soooo. It was working behaviour, but it's 'bad' style to use a body with a DELETE method so now NextJS throws an error. You have to use params instead of the request body in the function. |
Beta Was this translation helpful? Give feedback.
-
i am facing the same error,anybody know how to resolve it? |
Beta Was this translation helpful? Give feedback.
-
I got the error in the latest version on DELETE route what I did was to rollback to 13.2.4 which worked just fine. 13.3 and 13.4 got a couple issues. I am just learning but am sure some are finding same issues too |
Beta Was this translation helpful? Give feedback.
-
I have faced the same issue with POST (I was trying to get a value from the response's body and set it as a cookie). The solution for me was to clone the response using the clone() method. Hope it will help at least some of you. |
Beta Was this translation helpful? Give feedback.
-
I had the error : TypeError: Body is disturbed or locked when I was trying to call the function "res.text()" instead of "res.json()" |
Beta Was this translation helpful? Give feedback.
-
Hello, So, its's a time to close this issue 😎. I FOUND THE ERROR!!!. I really struggled so much of this headache error, after spending and debugging. at last without wasting time, YOU JUST WANNA TO REMOVE import { useRouter } from 'next/navigation'; and all of the things that was done by next/navigation in your using component. seems LIGHT, is'nt it? but it was true!!!!!!!!. HOPE YOU RESOLVED YOUR ISSUE :) |
Beta Was this translation helpful? Give feedback.
-
I've discovered this error has only been occurring for me when I've neglected to return a For example: export async function POST(req: any, res: NextApiResponse) {
const data: Array<Products> = await req.json();
try {
await dbConnect();
let result: Array<Products> = []
if (data.length) {
data.forEach(async (product) => {
let doc: Products | null = await Product.findOne({
name: product.name
});
if (doc) {
result.push(doc);
} else {
doc = await Product.create(product);
result.push(doc!);
}
return result
});
return NextResponse.json({ message: result, success: true });
} else {
return NextResponse.json({ message: result, success: false });
}
// NextRespose.json({...}) needs to be included here
} catch (err) {
return NextResponse.json({ error: err, success: false });
}
} I experienced this error MANY times when nesting responses within |
Beta Was this translation helpful? Give feedback.
-
For extra information; I just got the same error with Next 14.0.1 but I've not even implemented any backend service yet. I implemented a GraphQL server with Yoga as a POC beforehand, but this error is nothing to do with it since I got this error only when I save with any TypeScript error.
|
Beta Was this translation helpful? Give feedback.
-
I'm getting this error whenever I abort a fetch reqeust (like in useEffect cleanup function). |
Beta Was this translation helpful? Give feedback.
-
I'm getting this error with the same setting as @musabhusaini, using it as a webhook call through Supabase and http on insert of an element in the database. I see the error happening in both local and prod environments, what's even worse is that it sometimes work and I get no error, but no specifics on when it errors and when not, this is the route where I'm seeing the error: import { NextResponse } from 'next/server';
import Stripe from 'stripe';
import { createServerClient } from '@supabase/ssr';
import { cookies } from 'next/headers';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
export async function POST(req) {
if (req.method === 'POST') {
const cookieStore = cookies();
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.SUPABASE_SERVICE_ROLE_KEY,
{
cookies: {
get(name) {
return cookieStore.get(name)?.value;
},
set(name, value, options) {
cookieStore.set({ name, value, ...options });
},
remove(name, options) {
cookieStore.set({ name, value: '', ...options });
}
}
}
);
const body = await req.json();
if (!body.record.email) {
return new NextResponse('No email in body to create', { status: 200 });
}
const customer = await stripe.customers.create({
email: body.record.email
});
await supabase.from('profiles').update({ stripe_id: customer.id }).eq('id', body.record.id);
return new NextResponse('New Stripe user created', { status: 200 });
} else {
return new Response('Method Not Allowed', {
headers: { Allow: 'POST' },
status: 405
});
}
} Has anyone figured any solution for this yet? |
Beta Was this translation helpful? Give feedback.
-
Maybe dumb but I had to add e.preventDefault() to solve this problem. |
Beta Was this translation helpful? Give feedback.
-
I don't know if it matters, but what is suspicious for me is that in the DELETE function you once return the status in the first argument instead of the second one: |
Beta Was this translation helpful? Give feedback.
-
Meanwhile I have a theory that at least one possible reason for this could be that the page which called fetch for an API route is refreshed (or otherwise re-routed) while the API route is still being processed. Then, the next server cancels pending fetches for db accesses (in my case MongoDB) because the browser cancels the pending fetch because of the re-route and this leads to exceptions being thrown and those might cause the "TypeError: Response body object should not be disturbed or locked" error. |
Beta Was this translation helpful? Give feedback.
-
Now, I had another case where this error occurred: |
Beta Was this translation helpful? Give feedback.
-
Strapi + Next JsError happened in dev mode only but disappeared in production mode
|
Beta Was this translation helpful? Give feedback.
-
In my case, my routes were located under the /api folder, but I also had PayloadCMS which mounts its own routes published /api. When I moved my routes to another folder things worked again. It seems like PayloadCMS has a middleware that reads the request body on its way down the handler tree. |
Beta Was this translation helpful? Give feedback.
-
The problem seems fixed with the latest v14 version. |
Beta Was this translation helpful? Give feedback.
-
Hi, I've seen similar solution mentioned above, but not quite the same as I have. In my code, I was accessing incoming request body (like |
Beta Was this translation helpful? Give feedback.
-
Just for info - my issue was NOT api related (although the error came from there) - I was calling an API endpoint following an I needed to add a handler for the function eg: Noob error but caught me out :) |
Beta Was this translation helpful? Give feedback.
-
We had the same issue, turns out (in our case) it was calling the
Catching it in variable did the trick: |
Beta Was this translation helpful? Give feedback.
-
We had the same issue and were able to track it down to clients closing the socket before Next.js handled it: #63481 (comment) It was fixed last week and should be released in the latest canary. |
Beta Was this translation helpful? Give feedback.
-
const createContext = ({ Use this in server.ts |
Beta Was this translation helpful? Give feedback.
-
Hi :)
Since the upgrade from 13.2 to 13.3 and now 13.4, my
delete
fetch method doesn't works now and return the following error:It's the same on any fetch with the
delete
method but it's works withpost
orget
for example.I use the
app
router and my configuration is:I'am trying to upgrade to the latest canary release but it is the same.
An example of code with
delete
method and doesn't works now:And the api route where the
delete
method doesn't works but theget
andpost
method works:Any idea how what's happen ?
Thx for your help :)
Beta Was this translation helpful? Give feedback.
All reactions