Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Using `vc dev` .env has higher priority than .env.local | GoodFirstPicks

Using `vc dev` .env has higher priority than .env.local

vercel/next.js 12 comments 11d ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeTest focusedNext.jsTypeScriptReact

Why this is a good first issue

Environment variable loading order contradicts documented behavior

AI Summary

The issue reports that .env files are loading in reverse order of documented precedence, where .env.local should override .env but doesn't. This appears to be a bug in the environment variable loading implementation that needs investigation and potential fixes while considering backwards compatibility.

Issue Description

Bug report

Describe the bug

Doc states the following:

In general only one .env.local file is needed. However, sometimes you might want to add some defaults for the development (next dev) or production (next start) environment.

Next.js allows you to set defaults in .env (all environments), .env.development (development environment), and .env.production (production environment).

.env.local always overrides the defaults set.

Creating .env and .env.local setting the same TEST env variable and console.log shows that .env is actually overriding .env.local

To Reproduce

https://github.com/gabrielalmeida/nextjs-env-error-issue-17338

Expected behavior

.env.local values should be printed instead of .env "default" values

When running now dev, it actually does print the following wrong loading order for .env* files:

❯ now dev
Now CLI 20.0.0 dev (beta) — https://vercel.com/feedback
info  - Loaded env from /Users/gbr/Dev/env-override-error-repro/.env.local
info  - Loaded env from /Users/gbr/Dev/env-override-error-repro/.env
ready - started server on http://localhost:3000
event - compiled successfully
event - build page: /
wait  - compiling...
event - compiled successfully
.env .env. >>>>>>>>>>>>>> outputs .env instead of .env.local when console.log(process.env.NEXT_PUBLIC_TEST and process.env.TEST)

System information

  • OS: macOS
  • Version of Next.js: 9.5.3
  • Version of Node.js: v12.16.3

Additional context

The same unexpected behavior is present when using now dev or publishing to Vercel.

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!

Risk Flags

  • environment variable precedence
  • backwards compatibility
Loading labels...

Details

Points20 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedyes
Assigneeijjk