Using `vc dev` .env has higher priority than .env.local
See original GitHub issueBug 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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
@gabrielalmeida We can have it open here, this is something we would most likely fix with: https://github.com/vercel/next.js/pull/17152 - And tracking this issue is important. Thank you!.
hi, what’s the status here? I’m experiencing this problem on 10.2.0. tried to upgrade to 10.2.2 and still a problem. my issue:
.env
overriding.env.local
. my current workaround: use.env.development
instead of.env
. then.env.local
overrides.env.development