Build Failed on vercel
Unanswered
American Coot posted this in #help-forum
American CootOP
The Edge Function "middleware" size is 1.2 MB and your plan size limit is 1 MB
7 Replies
Post your middleware file
It’s too big so you need to reduce the file size prob by breaking it up into multiple functions
Also download the “import cost†extension to vscode if you haven’t already, it’ll tell you if a module you’re using is large in size. It’s possible one of your imports is massive and it could be reduced
@archer Also download the “import cost†extension to vscode if you haven’t already, it’ll tell you if a module you’re using is large in size. It’s possible one of your imports is massive and it could be reduced
American CootOP
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { routes } from "./utils/routes";
const publicRoutes: string[] = [];
const authRoutes: string[] = [routes.login];
export function middleware(request: NextRequest) {
const isAuthPage = authRoutes.includes(request.nextUrl.pathname);
const isPublicPage = publicRoutes.includes(request.nextUrl.pathname);
const TOKEN: string | undefined = request.cookies.get("token")?.value;
if (!TOKEN && !isPublicPage && !isAuthPage) {
const url = new URL(routes.login, request.nextUrl);
return NextResponse.redirect(url);
}
if (TOKEN && isAuthPage) {
const url = new URL(routes.home, request.nextUrl);
return NextResponse.redirect(url);
}
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - public/images
* - public/svg
*/
"/((?!api|_next/static|_next/image|favicon.ico|images|svg).*)",
],
};American CootOP
This is my dev server log
And this is what the "import cost" extension tells
American CootOP
it works when I comment out the "routes" object which contains all app routes I use it to centralize the routing in the project