Next.js Discord

Discord Forum

Route Handler POST 405 Method Not Allowed Error

Unanswered
Cuban Crocodile posted this in #help-forum
Open in Discord
Cuban CrocodileOP
I suddenly started getting a POST 405 Method Not Allowed Error on my Vercel deployments. I have an old commit/deployment where it works fine but now all new deployments seem to be breaking even with simple changes.

Specifically I tested the following setup:

/app/api/temp/route.ts
export async function POST(request: Request) {
  console.log("HERE IN TEMP POST ENDPOINT");
  console.log(request);

  return NextResponse.json(
    { data: "hello world" },
    {
      status: 200,
      statusText: "action done",
    }
  );
}

and I call this endpoint as follows:

console.log("RUNNING API TEMP");
      const tempRes = await fetch("/api/temp", {
        method: "POST",
        body: JSON.stringify({ data: "hello world" }),
      });
      const tempData = await tempRes.json();
      console.log(tempData);

      console.log("RUNNING API TEMP WITH FORMDATA");
      const tempRes2 = await fetch("/api/temp", {
        method: "POST",
        body: formData,
      });
      const tempData2 = await tempRes2.json();
      console.log(tempData2);


The first API call works fine (no 405 error) but when I pass in formData: const formData = new FormData(); formData.append("audioFile", audioBlob); it throws the 405 error for some reason. This works fine locally and it's only breaking in production. Any ideas on what might be happening? It's also weird because I only recently started getting this issue in the past ~12 hours. Thanks for the help!

4 Replies

Giant panda
yes, i'm having this issue too, started in the past ~~10 hours too.
but for me it's 404 -
Giant panda
@Cuban Crocodile

solved here:
#Server actions 🚨 BROKEN IN PRODUCTION 🚨 as of today Next@14.2.2

simply add

VERCEL_CLI_VERSION=vercel@33.7.1


in your Environment Variables on Vercel for your project
it appears to be a new cli problem
Cuban CrocodileOP
yes this works now thank you!