Variables defined in .env
files that do not begin with NEXT_PUBLIC_
are not available in Middleware deployed to Vercel
#67296
Labels
bug
Issue was opened via the bug report template.
Developer Experience
Issues related to Next.js logs, Error overlay, etc.
Middleware
Related to Next.js Middleware
Runtime
Related to Node.js or Edge Runtime with Next.js.
Webpack
Related to Webpack with Next.js.
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/flamboyant-cray-pwlc82
To Reproduce
.env
undefined
instead of the value defined in.env
Current vs. Expected behavior
Current
Variables defined in
.env
files that do not begin withNEXT_PUBLIC_
are not available in Middleware deployed to Vercel.BUT, all variables defined in Vercel are available in Middleware. This inconsistency is very confusing.
.env
files offer more functionality, e.g.MY_PATH="https://${VERCEL_URL}/some/path"
, so it would be great if it just worked.I have tried this workaround: #39705 (comment) but it extremely limited since some dependencies access variables using other syntax like
process.env[name]
.Expected
Consistent behaviour. If all environment variables defined in Vercel are made available to middleware, so too should all environment variables defined in
.env
files.Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 20.6.0: Tue Feb 22 21:10:42 PST 2022; root:xnu-7195.141.26~1/RELEASE_ARM64_T8101 Available memory (MB): 8192 Available CPU cores: 8 Binaries: Node: 20.10.0 npm: 10.2.3 Yarn: N/A pnpm: 8.15.4 Relevant Packages: next: 14.2.4 // Latest available version is detected (14.2.4). eslint-config-next: 14.2.4 react: 18.3.1 react-dom: 18.3.1 typescript: 5.5.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Developer Experience, Middleware, Runtime, Webpack
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
This issue is related to Vercel deployment, see the discussion here #39705
The text was updated successfully, but these errors were encountered: