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

Open
#5,195 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
51/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
node.js, typescript
Domain
backend, devops

Research direction

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.

Written by the indexing model from the issue text.

Description

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?
Dominant language
TypeScript
Stars
11.5k
Forks
968
Avg merge
4d 9h
Merged PRs (30d)
64

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nitrojs/nitro

All issues in nitrojs/nitro

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.