-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
[NEXT-1194] After upgrade to 13.3 request.json() in DELETE route handler fails #48096
Comments
+1 |
1 similar comment
+1 |
+1 Facing the issue with dev server. Production build works fine. |
+1 |
1 similar comment
+1 |
Due to a conflicting bug: vercel/next.js#48096
Similar error I'm using axios, Post works fine but delete dont work and leaves a status code 500 |
Same here... it worked previous versions, now I had to use url query parameters instead ... |
Still happens with 13.3.3 (dev and build) |
+1 |
Same, same |
same |
Same here |
Same issue |
yep still happens :( oh well back to 13.2.4 |
The problem exist also in 13.4.1 |
Phew. I'm not alone. 13.4.0 |
Kind of duplicate of: #48898 |
I am having the same issue with the POST endpoint. Debugging for two days, decided to switch back to /pages router and it works on first try. The app router is not ready for production yet, in my case atleast. |
i dont know if this will also work for delete i got this issue with POST where i wasn't able to get body
well i got work around for my problem like this hope it would be some use to everyone here |
also having this issue with route handler DELETE request, is there any update or simple workaround besides rolling back to an earlier version? |
- DELETE route error vercel/next.js#48096
I stumbled across this but then found that DELETE generally should not have a request body - the fact that nextjs previously supported it sounds like a bug to me:
Though it sounds frustrating if you were previously depending on this behavior... |
@alecf nice find, I’ve subsequently changed my request to pass query params and all is good again. Safe to upgrade to latest :) |
@alecf thanks. I use the following codes for those new to app /api and do not know how to get the query params.
|
|
Ainda com problemas na rota Delete, estou usando next 13.4.4 |
Just some clarity on method bodies. It's not common practice for methods other than PUT, POST and PATCH to have a body. There's no reason you can't have use a POST request for multiple purposes, as in, adding content and deleting, you could change the action depending on a URL param. That being said, obviously be extra careful not to delete content where you want to add it, and vice versa. 😅 As for the issue, I can't even get an empty DELETE request (without body) to work. 🥲 |
Working with next@13.4.4 by using POST Method facing this issue as well.here are the error messages. By useing request.body export async function POST(request: Request) {
const res = request.body;
} Throws
By useing request.json() export async function POST(request: Request) {
const res = request.json();
} Throws
By useing request.text() export async function POST(request: Request) {
const res = request.text();
} Throws
Could anyone tell me how can I retrive BODY in request ? 😿😿😿😿 |
use await |
The way that work for me with DELETE is using the params (same as the doc) and stop to use the body like other on top suggest export async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) maybe is not in the doc but the magic here is too create the route like this : --- api
--- myRouteFolder // named as you prefer
--- route.tsx
--- [myRouteFolderid] // create this folder to receive the ID for example
---route.tsx // add a new route file and here u go to create wherever u want to pass (id) to ur function for example : export async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
const { id } = params;
console.log("###", id)
} and then u just need to await fetch(`api/myRouteFolder/${deleteByID}`, {
method: "DELETE",
}); I hope it will be helpful |
Hi guys ! I just found working solution to get ID when performing DELETE Request ......
Basically what we are passing ID in our own header... On other hand in NextJS
It works for me... Thanks |
Thank you for your useful advice. By changing to |
any solution???
|
Add this to the bottom of your route file to make your route handler a dynamic route;
You need to make your route handler a dynamic route. NextJs failed to do this automatically, I think it has a bug that sets dynamic as See References |
+1: work in production, don't work in localhost |
+1 |
+1 Working with next@13.4.4 by using DELETE Method facing this issue as well.
|
You cant access request body for DELETE method, you can access the id from url. Example route structure: app/api/delete/[id]/route.ts
|
This comment was marked as resolved.
This comment was marked as resolved.
Unfortunately not, this question's specifically in relation to using DELETE in the route file. 😅 |
export async function DELETE(request: Request) { To perform the DELETE operation, you can make a request to the API endpoint with the id parameter specified in the URL: export const delete_post = async (id: string) => { and this worked for me! |
It looks like the `content-length` header can't be ignored for the request forwarded to the render worker. See nodejs/node#27880. Closes #48096, closes #49310. Fix NEXT-1194 fix NEXT-1114
@aniketbiprojit encountered what exactly? A fully static build can't have Route Handler that are not static, which is expected because there is no server. |
This issue was resolved for me upgrading to 13.4.16 |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
N/A
To Reproduce
Describe the Bug
I only encounter this error on the DELETE route handler. My POST and PUT route handlers can
await request.json()
with no issues.I run the same code in 13.2.4 and do not receive the error.
I am sending valid and very simple JSON:
Nevertheless, I receive this error:
Expected Behavior
I expect
await request.json()
to work as it does in the POST and PUT route handlers.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
NEXT-1194
The text was updated successfully, but these errors were encountered: