Description
Link to the code that reproduces this issue
https://github.com/hdodov/test-nextjs/tree/bug-env-too-large
To Reproduce
-
Import a large JSON file in your
next.config.js
(e.g. to use as redirects) -
Add some code that has to spawn a child process with the
child_process
module -
Run Next with
output: "standalone"
and in prod mode -
Run the app so that it runs the child process code
-
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:

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