vercel / vercel/next.js

`outputFileTracingRoot` silently excludes symlinked `node_modules` in standalone builds

Open
#83,294 4 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Output
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/ashi009/next.js-nft-bug

To Reproduce
  1. npm install
  2. npm run build
  3. node app/.next/standalone/server.js

The standalone output in app/.next/standalone/ will be missing files from symlinked node_modules, resulting in a broken release.

node:internal/modules/cjs/loader:1413
  throw err;
  ^

Error: Cannot find module './cpu-profile'
Require stack:
- .../next-js-nft-bug/app/.next/node_modules/next/dist/server/lib/start-server.js
- .../next-js-nft-bug/app/.next/standalone/server.js
    at Module.<anonymous> (node:internal/modules/cjs/loader:1410:15)
    at .../next-js-nft-bug/node_modules/next/dist/server/require-hook.js:57:36
    at defaultResolveImpl (node:internal/modules/cjs/loader:1051:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1056:22)
    at Module._load (node:internal/modules/cjs/loader:1219:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:238:24)
    at Module.<anonymous> (node:internal/modules/cjs/loader:1493:12)
    at mod.require (.../next-js-nft-bug/node_modules/next/dist/server/require-hook.js:68:28)
    at require (node:internal/modules/helpers:152:16) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '.../next-js-nft-bug/app/.next/node_modules/next/dist/server/lib/start-server.js',
    '.../next-js-nft-bug/app/.next/standalone/server.js'
  ]
}

Node.js v24.5.0
Current vs. Expected behavior

Expected: All required files, including those in symlinked node_modules outside outputFileTracingRoot, should be included in the standalone output, or the build should fail with a clear error.

Actual: Files outside outputFileTracingRoot (such as symlinked node_modules) are silently ignored, resulting in an unusable standalone build. The build succeeds but the application fails at runtime.

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: macOS 15.6.1
Binaries:
  Node: 24.5.0
  npm: 11.5.1
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.5.2
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.x
Which area(s) are affected? (Select all that apply)

Output

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

next build (local)

Additional context

This issue is especially problematic in CI environments, where it is common to symlink node_modules from a cached location to speed up environment setup. In these cases, the actual code for dependencies sits outside of the codebase and outside the outputFileTracingRoot. As a result, Next.js's NFT (output file tracing) feature fails to include these files in the standalone output.

More importantly, this failure is completely silent during build time—the build succeeds, but the resulting standalone output is broken and will only fail at runtime. This makes the issue very difficult to detect and debug in automated pipelines.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository, run npm install and npm run build, then launch app/.next/standalone/server.js to confirm the missing module. Trace the standalone output behavior around symlinked node_modules and outputFileTracingRoot; done means required files are included or the build reports a clear failure instead of producing a broken server.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, node.js
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.