We are experiencing persistent build failures on Vercel for our Next.js 15.2.3 project using Supabase. The builds fail consistently, even though the code builds and runs correctly locally using both npm run dev and npm run build.
The primary error occurs during the build process and seems to indicate file corruption specific to the Vercel environment. The build log consistently shows a TypeScript error originating from lib/supabase.ts, stating Type error: Cannot find name 'generateMetadata'. (or similar errors indicating extraneous text).
Example Error Snippet (from commit 5138b01 build log):
This shows extraneous text (seemingly from previous logs) being inserted into lib/supabase.ts at line 18 during the build, causing the syntax/type error.
Troubleshooting Steps Taken:
Verified the code builds and runs correctly locally.
MIguel - your recommendation was spot on. Thank You!!! However, we’re still facing issues:
Project Details:
Framework: Next.js 15.2.3 with App Router
Backend: Supabase
Deployment: Vercel
Problem: Our project builds and runs perfectly fine locally using next dev and next build. However, when deployed to Vercel, we encounter critical runtime errors:
Dynamic Product Pages (/products/[slug]): These pages fail to render, throwing a Supabase error:
Error: {"code":"PGRST201", ... "message":"Could not embed because more than one relationship was found for 'alternatives' and 'products'"}
This error occurs when fetching related “alternative” products. We’ve tried fetching alternatives using a two-step query (fetch IDs first, then fetch product details) and also tried adding explicit relationship hints (!alternatives_alternative_product_id_fkey) as suggested by the error, but the error persists specifically on Vercel deployments.
Dynamic Ingredient Pages (/ingredients/[slug]): These pages consistently return a 404 error on Vercel. We’ve added extensive console logging within the page component and its generateMetadata function, but no logs appear in the Vercel Runtime Logs when accessing these pages. This suggests the request fails before our page code is executed.
Troubleshooting Steps Taken:
Confirmed successful local builds (next build) and development server (next dev).
Verified all necessary environment variables (Supabase URL/keys) are correctly configured in Vercel project settings.
Updated page components and generateMetadata functions for dynamic routes to handle Next.js 15’s Promise-based params.
Removed the deprecated swcMinify option from next.config.ts.
Ensured generateStaticParams is correctly implemented (or removed for testing) on relevant dynamic routes.
Attempted simplifying data fetching logic within the affected pages (e.g., removing joins, returning static data from generateMetadata) without success in resolving the Vercel runtime issues.
Cleared Vercel Build Cache and Data Cache multiple times and redeployed.
Used git revert to undo recent changes and then re-applied fixes in new commits to rule out git state issues affecting Vercel builds.
Resolved earlier build issues caused by accidental file corruption (confirmed files are now clean).
Current Status: The Vercel build now succeeds (after fixing file corruption), but the runtime errors (PGRST201 on product pages, 404s on ingredient pages) remain unresolved and only occur on the Vercel deployment, not locally. The lack of logs for the 404 pages is particularly puzzling.
We suspect a potential issue with Vercel’s runtime environment, caching, or interaction with Supabase relationships/Next.js 15 dynamic routing that differs from the local environment.
Any insights or suggestions would be greatly appreciated!
Just to be thorough, I see you confirmed prod built locally. Did you run the prod build locally (npm start) and pointing to the prod supabase?
Typically an error like that suggests something more focused around supabase implementations rather than infrastructure (but not ruling anything out yet).
Lemme know this clarification, happy to keep digging in!