Build fails with "Error: Debug Failure." immediately after successful vite build

Build fails with “Error: Debug Failure.” immediately after successful vite build (Vite 5.4.21 + React)

I’m seeing a consistent build failure on Vercel where the build succeeds
through vite build completely, then crashes 0.5s later with no stack trace.

Build log pattern (every time):

vite v5.4.21 building for production…
transforming…
✓ 72 modules transformed.
rendering chunks…
computing gzip size…
dist/assets/favicon-.svg 0.27 kB
dist/index.html 1.86 kB
dist/assets/index-
.js 483.03 kB
✓ built in 2.3s
Error: Debug Failure.

Stack: Vite 5.4.21, @vitejs/plugin-react 4.2.0, React 18.2.0,
@supabase/supabase-js 2.39.0

What I’ve tried (all reproduce the identical failure):

  • Build cache enabled / disabled / “not available” (fresh project re-import)
  • Pinning Node.js to 20.x via “engines” in package.json (also tried
    default 24.x) — same crash either way
  • Reviewed every file in /api/ (5 serverless functions, all plain ES
    modules, no TypeScript syntax) — none appear malformed
  • Removed/renamed the one /api/ file that doesn’t export a default
    handler (api/rate-limit.js → _rate-limit.js, which Vercel ignores) —
    same crash

The exact same code builds with zero errors locally:
npm install && npm run build
→ ✓ built in 1.94s, no errors

Vercel support (Hobby plan) confirmed “Debug Failure” is a known
internal TypeScript compiler (tsc) crash, typically from their internal
build analyzer tracing Serverless Functions post-build, but couldn’t
pinpoint the specific cause without server-side log access (not
available on Hobby).

Has anyone seen this exact “Error: Debug Failure.” after a successful
vite build, and found what actually triggers it? Happy to share repo
structure or any config files that would help.

Deployment ref: dpl_7ZmbVXG3xpc28RL56aEwgk1NVJcT

Hi Tlstolz01,

Since vite build finishes successfully and the crash happens right after, I’d treat this as a Vercel post-build function detection/bundling issue, not a Vite/React bundle issue.

The quickest isolation test is to temporarily remove Vercel Functions from the deployment:

mv api _api_disabled

Deploy that test branch.

If the deployment succeeds, then the trigger is definitely inside /api. In that case, move the functions back one at a time until the failure returns.

A few things I’d check carefully in /api:

- every real function file exports a valid default handler or supported method export
- helper files are not living inside /api
- files renamed with a leading underscore are actually ignored by Vercel
- no generated/bundled file is unusually large or contains syntax Vercel’s function analyzer may parse differently
- no api file imports browser-only code from the Vite app

I’d move shared helpers outside the API folder, for example:

api/send-message.js
api/contact.js
lib/rate-limit.js
lib/supabase-server.js

Then import from lib/ instead of keeping non-route helper files inside /api.

If disabling /api still fails, then I’d compare the local Vercel build step rather than plain Vite:

npx vercel build --debug

Plain npm run build only proves the Vite static build works; vercel build is closer to what Vercel runs when it also discovers and bundles Functions.

Can you share the /api file list and which one first makes the test deployment fail?