Next.js Discord

Discord Forum

Unable to deploy facing "EDGE_FUNCTION_INVOCATION_FAILED". But working fine locally.

Answered
Allegheny mound ant posted this in #help-forum
Open in Discord
Allegheny mound antOP
Hey , I cant able to deploy my nextapp to vercel, after successfully deployment it is showing EDGE_FUNCTION_INVOCATION_FAILED error.

13 Replies

Allegheny mound antOP
this is the function Im creating an api route with:

import { NextRequest, NextResponse } from "next/server";
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";

export interface GetFileProps {
  url: string;
}

export const POST = async (
  req: NextRequest
): Promise<NextResponse<GetFileProps>> => {
  const { path } = await req.json();

  if (
    !process.env.NEXT_S3_REGION ||
    !process.env.NEXT_AWS_ACCESS_ID ||
    !process.env.NEXT_AWS_ACCESS_KEY ||
    !process.env.NEXT_S3_BUCKET_NAME
  ) {
    return NextResponse.json(
      { url: "" },
      { status: 500, statusText: "Missing environment variables" }
    );
  }

  const s3client = new S3Client({
    region: process.env.NEXT_S3_REGION,
    credentials: {
      accessKeyId: process.env.NEXT_AWS_ACCESS_ID,
      secretAccessKey: process.env.NEXT_AWS_ACCESS_KEY,
    },
  });

  const command = new GetObjectCommand({
    Bucket: process.env.NEXT_S3_BUCKET_NAME,
    Key: path as string,
  });

  const url = await getSignedUrl(s3client, command, { expiresIn: 30000 });

  return NextResponse.json({ url });
};
Its working locally but not when deployed and throw EDGE_FUNCTION_INVOCATION_FAILED
Toyger
check logs in vercel dashboard
Allegheny mound antOP
yeah I checked it
it is throwing this:
@Toyger
this is my middleware.ts file:
import { createMiddlewareClient } from "@supabase/auth-helpers-nextjs";
import { NextResponse } from "next/server";

import type { NextRequest } from "next/server";
import type { Database } from "@/lib/databaseTypes";

export async function middleware(req: NextRequest) {
  const res = NextResponse.next();

  // Create a Supabase client configured to use cookies
  const supabase = createMiddlewareClient<Database>({ req, res });

  // Refresh session if expired - required for Server Components
  await supabase.auth.getSession();

  return res;
}

// Ensure the middleware is only called for relevant paths.
export const config = {
  matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};
Toyger
Answer
Allegheny mound antOP
bruh
its working now
thanks man