#4648·nitro

cloudflare-module: 404 from env.ASSETS.fetch inherits the immutable _headers rule of its public-assets base, so browsers cache missing chunks for a year

Author: mrvnklmCreated Sep 21, 2026Updated Sep 22, 2026

Environment

  • nitropack 2.13.4 (via nuxt 4.5.2), preset cloudflare-module
  • wrangler 4.123.0, Workers Static Assets with "binding": "ASSETS"
  • The relevant code is identical on v2 and main.

Reproduction

Fresh app, no custom config:

bash
npx nuxi@latest init repro --template minimal
cd repro
NITRO_PRESET=cloudflare-module npx nuxi build

wrangler.jsonc:

jsonc
{
  "name": "nitro-404-repro",
  "main": ".output/server/index.mjs",
  "compatibility_date": "2025-07-15",
  "compatibility_flags": ["nodejs_compat"],
  "assets": { "directory": ".output/public", "binding": "ASSETS" }
}
bash
npx wrangler dev --port 8806
curl -sI http://localhost:8806/_nuxt/missing.js
# HTTP/1.1 404 Not Found
# Cache-Control: public, max-age=31536000, immutable

We see the same response in production on Cloudflare Workers.

Describe the bug

A request for a file that does not exist under a public-assets base with maxAge gets a 404 that the browser may cache for a year.

  1. For every publicAssets entry with maxAge and fallthrough: false, nitro derives a route rule cache-control: public, max-age=<maxAge>, immutable (src/core/config/resolvers/assets.ts#L47-L53). Nuxt registers /_nuxt/ this way.
  2. writeCFHeaders writes that rule to _headers as /_nuxt/* (src/presets/cloudflare/utils.ts#L108).
  3. The cloudflare-module entry returns env.ASSETS.fetch(request) for any path under such a base, before h3 runs (src/presets/cloudflare/runtime/cloudflare-module.ts#L21-L22).
  4. The asset layer applies the _headers rule to its 404 as well, and nitro passes that response through unchanged.

A 404 with an explicit max-age is cacheable (RFC 9111 §3), so the browser keeps "this chunk does not exist" for the full lifetime. A normal reload does not revalidate it; only a hard reload does. In a Nuxt app this surfaces as Failed to fetch dynamically imported module: …/_nuxt/<hash>.js that persists until the user hard-reloads, even after the chunk is available.

Because the entry forwards these paths before h3, neither server middleware nor route rules can fix this from app code.

Additional context

Expected: a 404 from the asset layer should not carry the long-lived cache-control meant for existing hashed files. For example, the entry could set cache-control: no-store on a 404 that env.ASSETS.fetch returns.

Workaround we use: a custom nitro.options.entry that wraps the preset handler.

typescript
import nitroHandler from 'nitropack/presets/cloudflare/runtime/cloudflare-module'

const LONG_LIVED = /immutable|max-age=[1-9]/i

export default {
  ...nitroHandler, // keeps scheduled/email/queue/tail/trace
  async fetch(request, env, ctx) {
    const res = await nitroHandler.fetch(request, env, ctx)
    if (res.status !== 404 || !LONG_LIVED.test(res.headers.get('cache-control') ?? '')) return res
    const copy = new Response(res.body, res)
    copy.headers.set('cache-control', 'no-store')
    return copy
  },
}

Not verified:

  • Why the chunk is briefly missing right after a deploy in the first place. We see the error shortly after deploys but have not measured the cause.
  • Whether cloudflare-pages behaves the same way. cloudflare-pages.ts uses the same isPublicAssetURL → env.ASSETS.fetch pattern, but we have not tested it.