Next.js Discord

Discord Forum

TypeError: Response body object should not be disturbed

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
Hello, anyone have interacted this problem
TypeError: Response body object should not be disturbed or locked

i make api request POST to http://localhost:3000/api/email/send

my code in the email/send/route.ts
simple:

import { NextRequest, NextResponse } from 'next/server';

export async function POST(request: NextRequest) {
const body = await request.json()
const { test } = body

console.log(test);

return NextResponse.json({ message: 'Email Send' });
}

but getting this error: TypeError: Response body object should not be disturbed or locked

I am on next 14,
when i dont send any raw Json like
{
"test": "Test"
}
i dont get error and the request passes

25 Replies

Transvaal lionOP
Hi, same error with json like
{
"test": "Test"
}
, without any json send i got "internal error" this time

if i remove this 2 lines:
const { test } = await request.json();

console.log(test);
and dont sent anything i got Email Send"
Transvaal lionOP
trough postman
@Transvaal lion trough postman
copy and paste this to body
{
    "test": "test"
}
Transvaal lionOP
same error: ⨯ TypeError: Response body object should not be disturbed or locked,

basically if i have json it does not work, if i dont have it works
Transvaal lionOP
we looking for this Content-Type - application/json?
yes
try this command
curl -X POST -d '{"test": "test"}' http://localhost:3000/api/email
Transvaal lionOP
i do have it set up at the screen I send you, but dont see it here
tried it
still sticking with the error
are you using custom server?
Transvaal lionOP
yes, I am using Payload CMS ecommerce template, it is with customs erver, is this the problem ?
oh god
@Transvaal lion yes, I am using Payload CMS ecommerce template, it is with customs erver, is this the problem ?
not sure, could you try create a new project and make the route and test again?
Transvaal lionOP
will do, thanks
@Transvaal lion will do, thanks
cool, let me know if it works
Transvaal lionOP
when you mention the custom server i found what i do wrong
did the same thing on the server and worked
thank you for the help
and pointing me in the right direction
@Transvaal lion thank you for the help
no prob, glad you fixed it