Vercel preset: missing paths always run the fallback function, even when every page is prerendered and a 404.html exists

Aperta
#5,195 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
51/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
backend, devops

Direzione di ricerca

Start by tracing the Vercel preset code that writes .vercel/output/config.json and the handling of vercel.config.routes; the issue does not name those source files. Compare its generated catch-all route with the cloudflare_module preset's not-found handling. Define and test how static 404 routing should interact with filesystem handling, prerendered pages, and server routes; done means missing paths serve the prerendered /404.html without invoking the fallback while server routes still work.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the feature

On a hybrid Nuxt build (nuxt build --preset vercel) where every page route is prerendered, any path with no file still goes to the server function. The last route Nitro writes to .vercel/output/config.json is

{ "src": "/(.*)", "dest": "/__fallback" }

so /no-such-page/, /wp-login.php, /.env and every other bot probe runs /__fallback to render a 404. That is the case even when /404.html is prerendered into .vercel/output/static/: the catch-all comes first, so the static page is never used.

Nitro already does the static thing for asset misses: after { "handle": "filesystem" } it writes "status": 404 routes for ^/_nuxt/(.*)$ and friends, so those never reach a function. We'd like a supported way to get the same for everything else.

Why it matters: sites like this need nuxt build only for a handful of server routes (here, one CMS preview endpoint) and are otherwise fully static. Each missing path is a function invocation, which on Vercel's paid plans is billed work that anyone can trigger. On Next.js the same kind of site serves its 404 from a static file.

Reproduction: https://github.com/KevinBlakeLopez/nuxt-hybrid-404-repro. Nuxt 4.7.0, nitropack 2.14.0, Node 24.14.1. No deployment needed:

pnpm install
WITH_404=1 pnpm build:vercel && pnpm check
404.html in static output: true
Routes after "filesystem" that return a static 404:
   ^/_nuxt/builds/meta/(.*)$
   ^/_nuxt/builds/(.*)$
   ^/_nuxt/(.*)$
Routes after "filesystem" that go to a function:
   ^(?<__isr_route>/__nuxt_error/?)$ -> /__fallback
   /api/preview -> /api/preview
   /__nuxt_error -> /__nuxt_error
   /__nuxt_island(?:/(?:.*))? -> /__nuxt_island/[...]
   /(.*) -> /__fallback
Last route (catches every path with no file): {"src":"/(.*)","dest":"/__fallback"}

On a real Vercel deployment of a similar app (Nuxt 4.x, nitropack 2.x, November 2026), unknown URLs returned 404 with x-vercel-cache: MISS and a function region in the request id on every request, while prerendered pages were cache HITs with no function.

What we found doesn't help:

  • vercel.config.routes can't do it. In the repro, a { src: '/(.*)', status: 404, dest: '/404.html' } route added there lands first in config.json, before { "handle": "filesystem" }, so it would 404 every page. The generated /(.*) -> /__fallback route is still written last.
  • nuxt generate gives a static 404 but drops the server routes.
  • A local build with Nitro 3.0.261103-rc (vercel preset) writes the same pair of catch-alls (/[...slug] and /__server), so this isn't fixed by upgrading. (Read in the build output, not deployed.)

Possible shapes (we're happy with whichever fits Nitro best):

  1. An opt-in option, for example vercel.staticNotFound: true, that ends the routes with { "src": "/(.*)", "status": 404, "dest": "/404.html" } instead of the fallback function, and prerenders /404.html if it isn't already.
  2. Do that automatically when every page route has prerender: true and a 404.html was prerendered.
  3. Let vercel.config add routes after the generated catch-all, or replace it.

For comparison, the cloudflare_module preset already gets close with existing options: cloudflare.deployConfig: true plus cloudflare.wrangler.assets.not_found_handling: '404-page' and a prerendered /404.html (the repro's WITH_404=1 pnpm build:cloudflare writes both). Per Cloudflare's docs that serves the static page to navigations without running the Worker; we haven't deployed it.

Additional information
  • Would you be willing to help implement this feature?
Lingua principale
TypeScript
Stelle
11.5k
Fork
968
Merge medio
4g 9h
PR unite (30g)
64

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nitrojs/nitro

Tutte le issue di nitrojs/nitro

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.