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
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:
- Use
path.join(process.cwd(), 'data', filename) instead of path.join(process.cwd(), filename) — Already done
- Add
turbopack.ignore in next.config.mjs to exclude specific paths from tracing
- Move the dynamic
fs operations to a separate file that is imported dynamically (import())
- Use
outputFileTracingExcludes in next.config.mjs to exclude directories
- Wait for upstream Next.js fix (may be resolved in 16.3+)
- The warning specifically traces to
next.config.mjs → app/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")
Problem
The Next.js 16.2.6 build produces a persistent Turbopack/NFT warning:
This happens because API routes (e.g.,
app/api/sin/orchestrator/stream/route.ts) usenode: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 buildproduces zero warnings.next/standalone/) does not include unnecessary project filesFiles to investigate / modify
Files to investigate
Technical Notes
fsoperations in server codefscalls at build time to determine what files to include in the standalone outputprocess.cwd()orpath.joinwith dynamic variables), it includes the entire projectpath.join(process.cwd(), 'data', filename)instead ofpath.join(process.cwd(), filename)— Already doneturbopack.ignoreinnext.config.mjsto exclude specific paths from tracingfsoperations to a separate file that is imported dynamically (import())outputFileTracingExcludesinnext.config.mjsto exclude directoriesnext.config.mjs→app/api/sin/orchestrator/stream/route.ts, suggesting the spawn call is the root causeRelated
spawn(BIN, ['orchestrator-run', task])execFile(BIN, ...)— BIN isprocess.env.SIN_CODE_BIN || 'sin-code'