Skip to content

Unused (dev) dependencies cause standalone node_modules pollution #77656

@ardokirsipuu

Description

@ardokirsipuu

Link to the code that reproduces this issue

https://github.com/ardokirsipuu/nextjs-standalone-node-modules

To Reproduce

  1. clone the repo
  2. run yarn
  3. run yarn build
  4. 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):

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OutputRelated to the the output configuration option.linear: nextConfirmed issue that is tracked by the Next.js team.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions