Next.js Discord

Discord Forum

Route Handler failing on Vercel but succeeding in Development

Cuckoo wasp posted this in #help-forum
Open in Discord
Cuckoo waspOP
I have the following call from the frontend:

useEffect(() => {
    async function getBuyer() {
      if (!item_id) {
      const response = await fetch(
          method: "GET",
          headers: { "Content-Type": "application/json" },
      const result = await response.json();
// more logic here
  }, [item_id, form]);

hitting the route handler endpoint:

export async function GET(req: NextRequest) {
  const searchParams = req.nextUrl.searchParams;
  const item_id = searchParams.get("item_id");
  const itemId = parseInt(item_id!);
  const pf_token = process.env.PF_TOKEN;

  var myHeaders = new Headers();
  myHeaders.append("Authorization", `Basic ${pf_token}`);

  var formdata = new FormData();
  formdata.append("podio_item_id", `${itemId}`);

  var requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: formdata,

  const results = await fetch(

  return new NextResponse(responseData, {
    headers: { "content-type": "application/json" },

The endpoint and frontend behave as expected locally, and the build was successful both locally and on deploy. I've ensured all of the environment variables are configured correctly in vercel.

However, when trying to use the same function in production, vercel logs the following error:

- error SyntaxError: Unexpected token I in JSON at position 0
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

It's the same error between request made via postman to the production api directly, and those made from the client component.

0 Replies