Skip to content

Automatic env file resolution is in reverse order of precedence #131

Description

@neverendingqs

The README says

The env resolution pattern follows the one used by Rail's dotenv and create-react-app

But the code says

const dotenvFiles = [
`.env.${env}.local`,
`.env.${env}`,
// Don't include `.env.local` for `test` environment
// since normally you expect tests to produce the same
// results for everyone
env !== 'test' && `.env.local`,
`.env`,
]
and
const envVarsArray = envFileNames.map((fileName) => {
const parsed = dotenv.config({ path: fileName })
return this.variableExpansion
? dotenvExpand(parsed).parsed
: parsed.parsed
})
return envVarsArray.reduce((acc, curr) => ({ ...acc, ...curr }), {})

That last .reduce() call means we're actually resolving the files in reverse order of precedence, since env vars in lower priority files are overwriting the ones in higher priority files.

The fix is potentially a breaking change, and so requires a major version bump.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions