Unverified Commit 1577ae5c authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Fix dotenv file loading order (#13161)

This matches the `dotenv` spec:
https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use

---

Closes #13015
parent 71d899f1
...@@ -68,8 +68,8 @@ If the same environment variable is defined multiple times, the priority of whic ...@@ -68,8 +68,8 @@ If the same environment variable is defined multiple times, the priority of whic
- Already defined environment variables have the higher priority. For example: `MY_KEY=value next dev` - Already defined environment variables have the higher priority. For example: `MY_KEY=value next dev`
- `.env.[environment].local` - `.env.[environment].local`
- `.env.[environment]`
- `.env.local` - `.env.local`
- `.env.[environment]`
- `.env` - `.env`
For example, consider the file `.env.local` with the following content: For example, consider the file `.env.local` with the following content:
......
...@@ -17,11 +17,11 @@ export function loadEnvConfig(dir: string, dev?: boolean): Env | false { ...@@ -17,11 +17,11 @@ export function loadEnvConfig(dir: string, dev?: boolean): Env | false {
const mode = isTest ? 'test' : dev ? 'development' : 'production' const mode = isTest ? 'test' : dev ? 'development' : 'production'
const dotenvFiles = [ const dotenvFiles = [
`.env.${mode}.local`, `.env.${mode}.local`,
`.env.${mode}`,
// Don't include `.env.local` for `test` environment // Don't include `.env.local` for `test` environment
// since normally you expect tests to produce the same // since normally you expect tests to produce the same
// results for everyone // results for everyone
mode !== 'test' && `.env.local`, mode !== 'test' && `.env.local`,
`.env.${mode}`,
'.env', '.env',
].filter(Boolean) as string[] ].filter(Boolean) as string[]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment