vercel / vercel/next.js

Unused (dev) dependencies cause standalone node_modules pollution

Open
#77,656 2 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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

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 yarn and yarn build, then inspect .next/standalone/node_modules and the outputFileTracingExcludes configuration described in the issue. Trace the standalone output produced by next build and compare it with the production runtime dependencies. Done means unused development dependencies such as esbuild and @rspack are no longer included without requiring many manual exclusions.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.