Skip to content

Variables defined in .env files that do not begin with NEXT_PUBLIC_ are not available in Middleware deployed to VercelΒ #18

@Calebmaloba

Description

@Calebmaloba

To Reproduce
next dev
observe that the middleware logs value as defined in .env
Deploy to Vercel
observe that the middleware logs undefined instead of the value defined in .env
Current vs. Expected behavior
Current
Variables defined in .env files that do not begin with NEXT_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: vercel/next.js#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 vercel/next.js#39705

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions