Persistent Build Failure - File Corruption During Build (Next.js 15)

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):

./lib/supabase.ts:18:3
Type error: Cannot find name 'generateMetadata'.

 [0m  [90m 16 | [39m  [36mif [39m ( [33m! [39msupabaseUrl  [33m|| [39m  [33m! [39msupabaseAnonKey) { [0m
 [0m  [90m 17 | [39m    [36mthrow [39m  [36mnew [39m  [33mError [39m( [32m'Missing Supabase environment variables' [39m) [33m; [39m [0m
 [0m [31m [1m> [22m [39m [90m 18 | [39m }[generateMetadata] and [ [33mIngredientPage [39m] [33mApr [39m  [35m01 [39m  [35m11 [39m [33m: [39m [35m48 [39m [33m: [39m [35m03.29 [39m [0m
 [0m  [90m    | [39m    [31m [1m^ [22m [39m [0m
 [0m  [90m 19 | [39m  [36mexport [39m  [36mconst [39m supabase  [33m= [39m createClient(supabaseUrl [33m, [39m supabaseAnonKey) [33m; [39m [0m
 [0m  [90m 20 | [39m [0m
 [0m  [90m 21 | [39m  [90m// Helper functions for common database operations [39m [0m

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.
  • Addressed potential Next.js 15 compatibility issues (Promise-based params, removed deprecated swcMinify).
  • Pushed multiple commits with fixes.
  • Cleared Vercel Build Cache via Project Settings → Git.
  • Cleared Vercel Data Cache via Project Settings → Data Cache.
  • Triggered multiple redeploys without using the build cache.
  • Attempted git revert and re-applying fixes in new commits.
  • Restored the affected file (lib/supabase.ts) locally using git checkout multiple times before committing/pushing.

Despite these steps, the file corruption error persists specifically within the Vercel build environment.

Is anyone else experiencing issues like this? Any recommended solutions? We’re pretty close to just starting over.

Hey, welcome!

from that message, it looks like your lib/supabase.ts has some code around line 18 that looks like:

[generateMetadata] and [IngredientPage]Apr 01 11:48:03.29

that was probably accidentally pasted into there and should be removed. That is just from decoding the characters in the snippet there.

Let me know, more than happy to help triage!

2 Likes

Thanks Miguel. I’ll check it out.

1 Like

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:

  1. 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.

  1. 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!

Awesome!

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!

1 Like