Link to the code that reproduces this issue
https://github.com/ardokirsipuu/nextjs-standalone-node-modules
To Reproduce
- clone the repo
- run
yarn
- run
yarn build
- check the contents of
.next\standalone\node_modules to find irrelevant (not needed for prod runtime) dependencies
Current vs. Expected behavior
Current behavior
When new (dev) dependencies are added, that are not used in the code, then the .next\standalone\node_modules folder is being polluted with additional files that are not needed for production runtime (e.g. esbuild, @esbuild/*, @rspack/* etc). See the screenshot below to see a diff of the file tree between before (HEAD~1) vs after (@nx/react is added):

Most of the tree on the left side shows new stuff being added (with a little twist of @swc/helpers actually being moved from the root to be under next/node_modules/@swc/helpers 👀).
Expected behavior
No unused files are added to .next\standalone\node_modules for unused dependencies.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Pro
Available memory (MB): 65277
Available CPU cores: 24
Binaries:
Node: 22.14.0
npm: 10.9.2
Yarn: 4.8.1
pnpm: N/A
Relevant Packages:
next: 15.3.0-canary.26
eslint-config-next: N/A
react: 19.1.0
react-dom: 19.1.0
typescript: 5.8.2
Next.js Config:
output: standalone
Which area(s) are affected? (Select all that apply)
Output
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
Having next.config.ts with something like
outputFileTracingExcludes: {
"./**/*": [
"node_modules/esbuild",
"node_modules/@esbuild",
],
},
would take care of these two excessive dependencies, but handling all those tens of dependencies manually like this would not be very feasible and would defeat the purpose of having the file tracing feature.
NEXT-4533
Link to the code that reproduces this issue
https://github.com/ardokirsipuu/nextjs-standalone-node-modules
To Reproduce
yarnyarn build.next\standalone\node_modulesto find irrelevant (not needed for prod runtime) dependenciesCurrent vs. Expected behavior
Current behavior
When new (dev) dependencies are added, that are not used in the code, then the
.next\standalone\node_modulesfolder is being polluted with additional files that are not needed for production runtime (e.g.esbuild,@esbuild/*,@rspack/*etc). See the screenshot below to see a diff of the file tree between before (HEAD~1) vs after (@nx/reactis added):Most of the tree on the left side shows new stuff being added (with a little twist of
@swc/helpersactually being moved from the root to be undernext/node_modules/@swc/helpers👀).Expected behavior
No unused files are added to
.next\standalone\node_modulesfor unused dependencies.Provide environment information
Which area(s) are affected? (Select all that apply)
Output
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
Having
next.config.tswith something likewould take care of these two excessive dependencies, but handling all those tens of dependencies manually like this would not be very feasible and would defeat the purpose of having the file tracing feature.
NEXT-4533