Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Response body object should not be disturbed or locked #14

Open
dutuka opened this issue Dec 7, 2023 · 10 comments
Open

TypeError: Response body object should not be disturbed or locked #14

dutuka opened this issue Dec 7, 2023 · 10 comments

Comments

@dutuka
Copy link

dutuka commented Dec 7, 2023

I have following error at 03:57:55

sign up doesnt work for me, i get 500 internal server error

image

On http://localhost:3000/sell/create-first-user it works, but doesnt work on http://localhost:3000/sign-up

Terminal log:

TypeError: Response body object should not be disturbed or locked

⨯ Error: No response is returned from route handler '\src\app\api\trpc[trpc]\route.ts'. Ensure you return a Response or a NextResponse in all branches of your handler.
at webpack://next/./dist/esm/server/future/route-modules/app-route/module.js:191:35

What can cause the issue?

@dutuka dutuka changed the title 500 internal server error | auth.createPayloadUser?batch=1 TypeError: Response body object should not be disturbed or locked Dec 7, 2023
@nikabilanych
Copy link

Hey, have you solved it? Mine for change returns a cast error when i try to create a new user

@dutuka
Copy link
Author

dutuka commented Dec 12, 2023

I still have the issue. I search for this error "TypeError: Response body object should not be disturbed or locked" and found some people having the same prolem said that it could be nextjs bug. I just wonder why it works in the tutorial but not for us.

@dutuka
Copy link
Author

dutuka commented Dec 12, 2023

Got it, turned out that i missed a slash before api path in the server.ts file:

app.use(
  "api/trpc",

It has to be:

app.use(
   "/api/trpc",

@nikabilanych
Copy link

I changed the zod schema validation (for email validation) kept on getting cast error w it when ive trued to sign up w my czech email adress for instance, and boom. Finally worked for me as well😂
Im glad we both figured it out 🤜🏼🤛🏼😁

@Huguesmmm
Copy link

Thank u @dutuka your solution worked for me, I had not even an TypedError but this one :
Error: No response is returned from route handler '.../digitalhippo/src/app/api/trpc/[trpc]/route.ts'. Ensure you return a Response or a NextResponse in all branches of your handler.

@ForeverRainmaN
Copy link

Hey!
Got the exact same issue here, is there any other ideas what can be the reason for that?

@zhoujingryan
Copy link

Got it, turned out that i missed a slash before api path in the server.ts file:

app.use(
  "api/trpc",

It has to be:

app.use(
   "/api/trpc",

same issue. thanks!

@devrudraa
Copy link

I changed the zod schema validation

Add a return before fetchRequestHandler and it will work
const handler = (req: Request) => {
return fetchRequestHandler({
endpoint: "/api/trpc",
req,
router: appRouter,
// @ts-expect-error context already passed from express middleware
createContext: () => ({}),
});
};

@devrudraa
Copy link

Got it, turned out that i missed a slash before api path in the server.ts file:

app.use(
  "api/trpc",

It has to be:

app.use(
   "/api/trpc",

I have the same issue even I wrote the path correctly why??

@steel-bucket
Copy link

steel-bucket commented Aug 16, 2024

Did anyone fix it? Neither Renaming to /api/trpc or adding the "return" in route.ts seem to be working for me

Edit: NVM I fixed it.

Another thing that can cause this error is if you put the nextHandler on top instead of bottom
The correct code in server.ts is

    app.use(
        '/api/trpc',
        trpcExpress.createExpressMiddleware({
            router: appRouter,
            createContext,
        })
    )
    app.use((req, res) => nextHandler(req, res))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants