-
Notifications
You must be signed in to change notification settings - Fork 30.7k
Next 16.2 won't load .env variables in Vercel at runtime #92116
Description
Link to the code that reproduces this issue
https://github.com/mordechaim/missing-env-repro
To Reproduce
Local version, working:
- Start the application locally (either dev or build/start)
- Observe both static, dynamic and cached contexts all have the correct value for MY_DOTENV
Deployed on Vercel:
- Open the Vercel deployed version at: https://missing-env-repro.vercel.app
- The static value is briefly shown the correct value (observable in the network tab page response) and quickly swapped out to
undefined - The dynamic value is
undefinedall along - The cached value correctly shows the variable
Current vs. Expected behavior
Since updating to Next 16.2 the runtime doesn't have access to variables defined in a committed .env file. During build time they all resolve correctly.
Variables set via the Vercel environment variables UI are properly set.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Pro
Available memory (MB): 32189
Available CPU cores: 14
Binaries:
Node: 25.0.0
npm: 11.6.2
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 16.2.1-canary.13 // Latest available version is detected (16.2.1-canary.13).
eslint-config-next: N/A
react: 19.2.4
react-dom: 19.2.4
typescript: 5.9.3
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)
Module Resolution, Runtime
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
I used cacheComponents to demonstrate the difference between build-time and dynamic access; but the same behavior is observed when using fully static (correctly set) and fully dynamic (missing) pages.
There's a hydration error printed to the browser console, as the static value is swapped out at runtime to undefined.
The cached value is showing the value at build time, and since I added "use cache", the value isn't swapped out during hydration.