#4679·nitro

`nitro build` silently deletes a `publicAssets` dir that sits inside the output dir

Author: gleknerCreated Sep 28, 2026Updated Sep 28, 2026

nitro build calls prepare(), which rm -rfs the output dirs, before copyPublicAssets(). If a publicAssets dir lives inside one of them (e.g. dist/client with netlify or cloudflare-pages, which publish from dist/), it gets deleted. copyPublicAssets() then skips the missing dir without a warning and the build reports success.

Repro

typescript
// nitro.config.ts
import { defineConfig } from "nitro";

export default defineConfig({
  preset: "netlify",
  publicAssets: [{ dir: "dist/client" }],
});
bash
npm i [email protected]
mkdir -p dist/client && echo 'console.log(1)' > dist/client/app.js
npx nitro build     # ✔ Generated public dist
find dist -type f   # dist/_headers, dist/_redirects (app.js is gone)

Expected: the build fails, or at least warns, that dist/client is inside a dir that gets cleaned. Actual: dist/client is deleted and the build succeeds with no client assets.

Versions: nitro 3.0.260903-beta and nitro-nightly 3.0.1-20260928-103646-f72e2ba6. main at 9cf83c8 hasn't changed these files since.

Possible fix: in prepare() (src/build/prepare.ts:4-12), throw if any publicAssets[].dir is inside a dir it's about to remove. nitro/vite isn't affected because it runs prepare() before any environment builds (src/build/vite/plugin.ts:371).