Repository navigation
Description
Environment
Nitro: 2.13.4 (also present on main, see below)
Node: v24.20.0
Package manager: [email protected]
OS: macOS (also reproduced on linux CI)
Preset: node-server
Reproduction
npm install && npm run build && npm run check
Describe the bug
generateFSTree globs the server output to print the size report, without disabling symlink traversal:
// src/core/utils/fs-tree.ts (v2) · src/utils/fs-tree.ts (main)
const files = await globby("**/*.*", { cwd: dir, ignore: ["*.map"] });followSymbolicLinks defaults to true in both globby (v2) and tinyglobby (main). But the directory being measured is built out of directory symlinks that nitro creates itself — a package traced in more than one version is written to .nitro/<pkg>@<version> and linked into place, both flat and under each parent. Every file behind those links is therefore reached by several paths, and read — with compressedSizes: true, gzipped — once per path.
The reproduction reports 25.2 MB for a 5.2 MB output: one 5 MB file counted five times. The log contradicts itself without any extra measurement — the tree lists six files totalling ~152 kB and then claims 25.2 MB, because files under node_modules are added to the total but skipped when printing.
In a production Nuxt 4.5 app the effect scales with the number of multi-version externals:
| paths | unique files | Σ | glob | |
|---|---|---|---|---|
| as globbed today | 413250 | 11415 | 1.72 GB | 37000 ms |
followSymbolicLinks: false |
5660 | 5660 | 65.0 MB | 259 ms |
followSymbolicLinks: false, dot: true |
11062 | 11062 | 84.6 MB | 479 ms |
find . -type f (ground truth) |
— | 11506 | 87.1 MB | — |
Our CI printed Σ Total size: 1.75 GB for a 111 MB output, and spent 98 s on that single line — a third of a 4-minute build. We had to set nitro.logLevel: 1 to disable it.
Note that followSymbolicLinks: false alone under-counts: the only real copies live in .nitro/, and globs skip dot-directories by default. Both options are needed to match the ground truth.
The same call has a second, smaller defect: ignore: ["*.map"] lacks **/, so only root-level sourcemaps are excluded — 442 nested ones ended up in our report.
Suggested fix, identical in both branches:
const files = await glob("**/*.*", {
cwd: dir,
ignore: ["**/*.map"],
followSymbolicLinks: false,
dot: true,
});Additional context
Possibly related: #1833 (heap out of memory on outputs with many files) and the two mitigations that came out of it, #2145 / #2458, which capped concurrent open files in this same function. Those addressed the symptom; reading each file dozens of times may be the underlying cause. I would not claim that without checking their outputs, though.
Activity
fix(build): count each output file once in the size report
fix(build): count each output file once in the size report