Skip to content

outputFileTracingIncludes Not Including Files in App Router Route with Dynamic fs.readFile #80660

@neelbrahmakshatriya

Description

@neelbrahmakshatriya

Link to the code that reproduces this issue

https://shadcn-studio-internal-staging.vercel.app/blocks

To Reproduce

  1. Create a Next.js 15 app using App Router.
  2. Add some .tsx files in src/registry/new-york/blocks/.
  3. In a route like src/app/(blocks-inner-pages)/blocks/[category]/[section]/page.tsx, call a function from the src/lib/registry.ts file that calls fs.readFile(...) pointing to the files mentioned in the second step.
  4. Add outputFileTracingIncludes targeting that route in next.config.ts like the following:
import path from 'path'
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  outputFileTracingIncludes: {
    './src/app/(blocks-inner-pages)/blocks/[category]/[section]/page.tsx': [
      './src/registry/new-york/blocks/**/*.tsx',
      './src/lib/registry.ts',
      './src/registry/registry-blocks.ts'
    ]
  }
  1. Run next build and observe that files are not present in .next.

Current vs. Expected behavior

Problem

Despite using outputFileTracingIncludes correctly to include files used via dynamic fs.readFile() calls in a server component route, the files are not being traced, copied, or included in the .next build output - either locally or on Vercel.


Details

  • I'm dynamically reading .tsx files at runtime using:
fs.readFile(path.join(process.cwd(), file.path), 'utf-8')
  • The files are stored in:
    src/registry/new-york/blocks/**/*.tsx

  • The code that calls fs.readFile lives inside the src/lib/registry.ts file and the function is being called from the following:
    src/app/(blocks-inner-pages)/blocks/[category]/[section]/page.tsx

  • My next.config.ts includes:

import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  outputFileTracingIncludes: {
    './src/app/(blocks-inner-pages)/blocks/[category]/[section]/page.tsx': ['./src/registry/new-york/blocks/**/*.tsx', './src/lib/registry.ts', './src/registry/registry-blocks.ts']
  }
}

Actual Behavior

  • After running next build, no files from registry/new-york/blocks appear in .next/ output.

  • Confirmed with:

    find .next -type f | grep new-york/blocks
  • This also causes fs.readFile to fail in the deployed app on Vercel because the files are missing.


Expected Behavior

All files in src/registry/new-york/blocks should be included in the .next build output and deployed to Vercel so they are available for runtime access via fs.readFile().

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.2.0: Fri Dec  6 18:40:14 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T8103
  Available memory (MB): 8192
  Available CPU cores: 8
Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: 1.22.19
  pnpm: 10.6.2
Relevant Packages:
  next: 15.3.2 // There is a newer version (15.3.3) available, upgrade recommended! 
  eslint-config-next: 15.3.2
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.5.4
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Runtime

Which stage(s) are affected? (Select all that apply)

next build (local), Vercel (Deployed)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    RuntimeRelated to Node.js or Edge Runtime with Next.js.invalid linkThe issue was auto-closed due to a missing/invalid reproduction link. A new issue should be opened.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions