vercel / vercel/next.js

Large `__NEXT_PRIVATE_STANDALONE_CONFIG` causes `Error: spawn E2BIG`

Open
#80,663 0 comments 7 reactions 1 assignee View on GitHub

@devjiwonchoi is already working on this.

Since Aug 14, 2025.

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

Description

Link to the code that reproduces this issue

https://github.com/hdodov/test-nextjs/tree/bug-env-too-large

To Reproduce
  1. Import a large JSON file in your next.config.js (e.g. to use as redirects)

  2. Add some code that has to spawn a child process with the child_process module

  3. Run Next with output: "standalone" and in prod mode

  4. Run the app so that it runs the child process code

  5. You'll see this error:

     ⨯ Error: spawn E2BIG
        at d (.next/server/app/page.js:1:2287)
        at l (.next/server/app/page.js:1:2358) {
      errno: -7,
      code: 'E2BIG',
      syscall: 'spawn',
      digest: '1763947400'
    }
    

When logging process.env, you can see that basically the entire JSON file is put in an environment variable:

Image

That's what causes the E2BIG error, which happens when a process is spawned with either too long arguments or a too large set of environment variables.

Current vs. Expected behavior

Currently, you get a warning in dev mode, if you have too many redirects:

$ pnpm dev                            

> test-nextjs@0.1.0 dev /Users/hristiyan.dodov/Projects/test-nextjs
> next dev

   ▲ Next.js 15.3.3
   - Local:        http://localhost:3000
   - Network:      http://192.168.1.129:3000

 ✓ Starting...
Warning: total number of custom routes exceeds 1000, this can reduce performance. Route counts:
headers: 0
rewrites: 0
redirects: 2500
See more info: https://nextjs.org/docs/messages/max-custom-routes-reached
 ✓ Ready in 2.5s

What I'm expecting is to also see a warning that an environment variable will hold ALL OF THEM as JSON.

For my case, the performance impact was negligible and it wasn't a problem. But the fact that we had ~0.5MB in environment variables surely was.

Provide environment information
Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 23.6.0: Thu Apr 24 20:26:36 PDT 2025; root:xnu-10063.141.1.705.2~1/RELEASE_X86_64
  Available memory (MB): 32768
  Available CPU cores: 16
Binaries:
  Node: 20.17.0
  npm: 10.8.2
  Yarn: N/A
  pnpm: 10.4.1
Relevant Packages:
  next: 15.3.3 // Latest available version is detected (15.3.3).
  eslint-config-next: 15.3.3
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
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 start (local)

Additional context

No response

NEXT-4662

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.