Skip to content

fix: Eliminate Turbopack/NFT build warning #53

@Delqhi

Description

@Delqhi

Problem

The Next.js 16.2.6 build produces a persistent Turbopack/NFT warning:

Turbopack build encountered 1 warnings:
./next.config.mjs
Encountered unexpected file in NFT list
A file was traced that indicates that the whole project was traced unintentionally.

This happens because API routes (e.g., app/api/sin/orchestrator/stream/route.ts) use node:child_process (spawn/execFile), which causes Turbopack's Node File Tracing (NFT) to conservatively include the entire project directory in the standalone output.

While the build succeeds, this warning indicates the bundle is larger than necessary and may include files that shouldn't be in the production server.

Goal

Eliminate the NFT warning by ensuring all filesystem operations are statically scoped to specific subdirectories, or by suppressing the trace for dynamic paths.

Acceptance Criteria

  • pnpm build produces zero warnings
  • The standalone output (.next/standalone/) does not include unnecessary project files
  • Build time is not significantly increased
  • Alternative: Document the warning as a known upstream issue if no fix is possible

Files to investigate / modify

Files to investigate

app/api/sin/orchestrator/stream/route.ts    # Uses spawn() — potential NFT trigger
lib/sin/run.ts                            # Uses execFile() with BIN path
lib/chat-history.ts                       # Uses path.join(process.cwd(), ...)
lib/audit.ts                              # Uses path.join(process.cwd(), ...)
lib/shares.ts                             # Uses path.join(process.cwd(), ...)
lib/tokens.ts                             # Uses path.join(process.cwd(), ...)
lib/workspaces.ts                         # Uses path.join(process.cwd(), ...)
next.config.mjs                           # May need turbopack.ignore or outputFileTracingExcludes

Technical Notes

  • Next.js 16.2.6 Turbopack has a known limitation with dynamic fs operations in server code
  • The NFT tracer analyzes fs calls at build time to determine what files to include in the standalone output
  • When it sees unbounded dynamic paths (like process.cwd() or path.join with dynamic variables), it includes the entire project
  • Potential fixes:
    1. Use path.join(process.cwd(), 'data', filename) instead of path.join(process.cwd(), filename)Already done
    2. Add turbopack.ignore in next.config.mjs to exclude specific paths from tracing
    3. Move the dynamic fs operations to a separate file that is imported dynamically (import())
    4. Use outputFileTracingExcludes in next.config.mjs to exclude directories
    5. Wait for upstream Next.js fix (may be resolved in 16.3+)
  • The warning specifically traces to next.config.mjsapp/api/sin/orchestrator/stream/route.ts, suggesting the spawn call is the root cause

Related

  • AGENTS.md §5.7: Build warnings should be eliminated before shipping
  • app/api/sin/orchestrator/stream/route.ts: Uses spawn(BIN, ['orchestrator-run', task])
  • lib/sin/run.ts: Uses execFile(BIN, ...) — BIN is process.env.SIN_CODE_BIN || 'sin-code'
  • Next.js upstream issue: https://github.com/vercel/next.js/issues/ (search for "Turbopack NFT unexpected file")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions