Skip to content

Nitro: outputFileTracingIncludes / outputFileTracingExcludes are ignored, so externals ship incomplete #5131

Backlog

Description

@AhmedElBanna80

Problem

Under Nitro, a server-external package that reads its own non-JS files at runtime ships incomplete in .output/server/node_modules, even when the app lists those files in outputFileTracingIncludes. vinext does not read outputFileTracingIncludes or outputFileTracingExcludes from next.config.

Repro

Next.js's test/e2e/twoslash fixture: serverExternalPackages: ["twoslash"] plus

outputFileTracingIncludes: {
  "/": ["<path to node_modules/typescript/lib>/lib.*.d.ts", "./node_modules/@types/node/**"],
},

Build with vinext() + nitro({ preset: "bun" }) on 1.0.0-beta.12. .output/server/node_modules/typescript/lib contains only typescript.js while the app's copy has 100 files, and @types/node is not copied at all. The route returns {"error":{}} because @typescript/vfs cannot find lib.es2020.d.ts and the other lib files.

Expected

Files matched by outputFileTracingIncludes ship in the server output, and outputFileTracingExcludes removes traced files, as in Next.js.

Cause

Nitro traces externalized packages file by file, so it misses files only read with fs at runtime. Next.js covers that case with the two options; vinext never parsed them.

A fix is up in #3436.

Activity

  1. added
    bug
    on Dec 5, 2026
  2. alcora-dev commented on Dec 5, 2026

    @alcora-dev
    Contributor

    Triage: reproduced

    Thanks for the clear report. You're right: vinext doesn't read outputFileTracingIncludes or outputFileTracingExcludes from next.config at all. In a Nitro production build it only passes serverExternalPackages to Nitro's dependency tracing. Nitro copies each external package one module at a time, so files the package only reads with fs at runtime are left out, even when you list them in outputFileTracingIncludes. That's why typescript/lib arrives without its lib.*.d.ts files and @types/node is missing.

    We saw the same thing with a small App Router app: a server-external package with an extra file listed in outputFileTracingIncludes, built with vinext() and nitro(). The file was missing from .output/server/node_modules, while next build records it in the route's trace. Excludes aren't applied either, for the same reason.

    Until this is fixed, a workaround is to copy the files into .output/server/node_modules after the build, or to add them through Nitro's own options.

    Details for maintainers

    Cause: vinext never reads outputFileTracingIncludes or outputFileTracingExcludes from next.config. Its Nitro setup hook only adds serverExternalPackages to Nitro's traceDeps, and Nitro traces externals module by module, so files an external package only reads with fs at runtime are left out of .output/server/node_modules. A Nitro build of a checked-in fixture that includes node_modules/pathslash/README.md ships only dist and package.json. Not checked: the Turbopack probe failed because of the symlinked scratch setup (a webpack next build does record the included file in the route's .nft.json), and PR #3436 couldn't be read without GitHub access.

    Where to look:

    • packages/vinext/src/config/next-config.ts:2304 config resolution reads serverExternalPackages but never parses outputFileTracingIncludes / outputFileTracingExcludes (route-keyed glob maps, resolved from the project dir) into the resolved config
    • packages/vinext/src/index.ts:9638 vinext:nitro-setup only adds serverExternalPackages to nitro.options.traceDeps; included files need to be copied into Nitro's output server dir (and excluded ones dropped), e.g. from a Nitro hook after externals are traced
    • packages/vinext/src/build/standalone.ts:249 vinext's own output: "standalone" copy also never applies these options; the same missing parse probably affects it, and it belongs in the same minimal fix

    Reproduction: npx vp test run tests/nitro-output-file-tracing.repro.test.ts
    The command exited with 1 on a clean checkout.

    Expected: Files matched by outputFileTracingIncludes are copied into the Nitro server output (.output/server/node_modules/...), and files matched by outputFileTracingExcludes are removed, as in Next.js.
    Observed: .output/server/node_modules/pathslash contains only dist and package.json; the included README.md is missing, and the test fails with "expected [ 'dist', 'package.json' ] to include 'README.md'".

    The test: tests/nitro-output-file-tracing.repro.test.ts
    import fs from "node:fs";
    import path from "node:path";
    import { createRequire } from "node:module";
    import { pathToFileURL } from "node:url";
    import { createBuilder, type PluginOption } from "vite";
    import { afterAll, beforeAll, describe, expect, it } from "vite-plus/test";
    import vinext from "../packages/vinext/src/index.js";
    import { createIsolatedFixture } from "./helpers.js";
    
    // Issue #5131: under Nitro, vinext ignores outputFileTracingIncludes, so a
    // server-external package that reads its own non-JS files at runtime ships
    // without them in .output/server/node_modules.
    const FIXTURE_DIR = path.resolve(
      import.meta.dirname,
      "fixtures/nitro-output-file-tracing/app-root",
    );
    // The workspace fixture that has Nitro installed.
    const NITRO_FIXTURE = path.resolve(import.meta.dirname, "fixtures/app-router-nitro-server");
    
    describe("Nitro build honours outputFileTracingIncludes", () => {
      let root: string;
      let serverModules: string;
    
      beforeAll(async () => {
        root = await createIsolatedFixture(FIXTURE_DIR, "vinext-nitro-tracing-");
        const nitroVite = createRequire(path.join(NITRO_FIXTURE, "package.json")).resolve("nitro/vite");
        const { nitro } = (await import(pathToFileURL(nitroVite).href)) as {
          nitro: (options?: Record<string, unknown>) => PluginOption;
        };
        const builder = await createBuilder({
          root,
          configFile: false,
          plugins: [
            vinext({ appDir: root }),
            nitro({ preset: "node-server", serveStatic: false, buildDir: path.join(root, ".nitro") }),
          ],
          logLevel: "error",
        });
        await builder.buildApp();
        serverModules = path.join(root, ".output/server/node_modules");
      }, 300_000);
    
      afterAll(() => {
        if (root) fs.rmSync(root, { recursive: true, force: true });
      });
    
      it("externalizes the server-external package into the Nitro output", () => {
        expect(fs.existsSync(path.join(serverModules, "pathslash/package.json"))).toBe(true);
      });
    
      it("ships files matched by outputFileTracingIncludes", () => {
        expect(fs.readdirSync(path.join(serverModules, "pathslash"))).toContain("README.md");
      });
    });
    What it printed
    RUN  v5.1.0 /workspace/repo
    
     ❯  unit  tests/nitro-output-file-tracing.repro.test.ts (2 tests | 1 failed) 4016ms
       ❯ Nitro build honours outputFileTracingIncludes (2)
         ✓ externalizes the server-external package into the Nitro output 2ms
         × ships files matched by outputFileTracingIncludes 3ms
    
     Test Files  1 failed (1)
          Tests  1 failed | 1 passed (2)
       Start at  09:41:47
       Duration  5.46s (tests 76%, transform 13%, import 8%, setup 3%)
    
    
    
    
    ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
    
     FAIL   unit  tests/nitro-output-file-tracing.repro.test.ts > Nitro build honours outputFileTracingIncludes > ships files matched by outputFileTracingIncludes
    AssertionError: expected [ 'dist', 'package.json' ] to include 'README.md'
     ❯ tests/nitro-output-file-tracing.repro.test.ts:52:67
         50|
         51|   it("ships files matched by outputFileTracingIncludes", () => {
         52|     expect(fs.readdirSync(path.join(serverModules, "pathslash"))).toCo…
           |                                                                   ^
         53|   });
         54| });
    
    ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
    

    Triaged by an AI agent at 5974ee6; it may be wrong. Confidence: high. · Triage report · Run #135

  3. alcora-dev commented on Dec 5, 2026

    @alcora-dev
    Contributor

    A fix is ready for review: #5134

    A pull request fixes this, with the reproduction kept as a regression test. ask-bonk[bot] approved its head, and its checks pass: it is waiting for a maintainer.

    Fixed by an AI agent; it may be wrong. · Triage report · Run #1289

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions