-
Notifications
You must be signed in to change notification settings - Fork 26.7k
-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using vc dev
.env has higher priority than .env.local
#17338
Comments
Judging by its implementation in load-env-config.ts I think it might be the docs that are wrong here. Changing the order will break existing builds relying on these stacked config files, and would make for an awkward upgrade process as a result. |
@gabrielalmeida Can you try reproducing that behavior in this example: https://github.com/vercel/next.js/tree/canary/examples/environment-variables 🙏 |
Even though the implementation at load-env-config.ts seems misleading at first because of the reverse order: const dotenvFiles = [
`.env.${mode}.local`,
// Don't include `.env.local` for `test` environment
// since normally you expect tests to produce the same
// results for everyone
mode !== 'test' && `.env.local`,
`.env.${mode}`,
'.env',
] It's actually matching the expected behavior of the docs, because it's only applying a new value if it was not present earlier on a higher priority for (const key of Object.keys(result.parsed || {})) {
if (
typeof parsed[key] === 'undefined' && <---- Will only override if not defined by anyone earlier on the loop
typeof origEnv[key] === 'undefined'
) {
parsed[key] = result.parsed?.[key]!
}
} After acknowledging this, I've realized that the issue was elsewhere. Digging further, I've noticed that I've been starting my The Vercel CLI will automatically look for a
So the pesky gotcha is, use I'd close this if there was a way to avoid this error when publishing via Vercel CLI, because as soon you type Should I close this one and reference it on a new issue at |
vc dev
.env has higher priority than .env.local
@gabrielalmeida We can have it open here, this is something we would most likely fix with: #17152 - And tracking this issue is important. Thank you!. |
Cool, that PR seems to be the way to go! Just a heads up that this is not exclusive to I haven't tested though if checking a |
I'd like to add to this, any dotenv set ups that require my temp solution for those who need it
|
Previously I use v10.0.2. and it works as expected:
But after I upgrade to v10.0.8, it does not work anymore. |
I just tried v10.0.7, it works too, |
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. |
Bug report
Describe the bug
Doc states the following:
Creating
.env
and.env.local
setting the sameTEST
env variable andconsole.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" valuesWhen running
now dev
, it actually does print the following wrong loading order for.env*
files:System information
Additional context
The same unexpected behavior is present when using
now dev
or publishing to Vercel.The text was updated successfully, but these errors were encountered: