Skip to content

Next 16.2 won't load .env variables in Vercel at runtime #92116

@mordechaim

Description

@mordechaim

Link to the code that reproduces this issue

https://github.com/mordechaim/missing-env-repro

To Reproduce

Local version, working:

  1. Start the application locally (either dev or build/start)
  2. Observe both static, dynamic and cached contexts all have the correct value for MY_DOTENV

Deployed on Vercel:

  1. Open the Vercel deployed version at: https://missing-env-repro.vercel.app
  2. The static value is briefly shown the correct value (observable in the network tab page response) and quickly swapped out to undefined
  3. The dynamic value is undefined all along
  4. 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/A

Which 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.

Metadata

Metadata

Assignees

Labels

Module ResolutionModule resolution (CJS / ESM, module resolving).RuntimeRelated to Node.js or Edge Runtime with Next.js.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions