Skip to content
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

variables overwriting/priority does not match Next.js #83

Closed
timhettler opened this issue Oct 30, 2023 · 4 comments
Closed

variables overwriting/priority does not match Next.js #83

timhettler opened this issue Oct 30, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@timhettler
Copy link

The file priority for this project does not match the convention in Next.js

  1. process.env
  2. .env.$(NODE_ENV).local
  3. .env.local (Not checked when NODE_ENV is test.)
  4. .env.$(NODE_ENV)
  5. .env

(See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order)

It would be great to have an option to match this convention.

@kerimdzhanov
Copy link
Owner

kerimdzhanov commented Nov 1, 2023

Hi @timhettler,

Thanks for the suggestion.

Interesting… So, as far as I understand, the difference is that .env.local has priority over .env.${NODE_ENV}. It definitely makes some kind of sense.

I'm thinking about the name and variations of the option and considering "order" or "priority" cannot imagine anything obvious/easy to read. The only readable solution I could imagine so far is providing a list of files in the order you'd like them to be loaded. It would look something like this:

require('dotenv-flow').config({
  files: [
    '.env',
    `.env.${process.env.NODE_ENV}`,
    '.env.local',
    `.env.${process.env.NODE_ENV}.local`,
  ]
});

(shell/predefined variables will always have a priority over those defined in env files)

Any other ideas?

@timhettler
Copy link
Author

This solution definitely gives the user the most control! Alternatively, as a convenience, you could provide something like sortingStyle?: 'nextjs' | 'default' config option. I'm not aware if there are other frameworks that use a different convention.

@kerimdzhanov kerimdzhanov added the enhancement New feature or request label Nov 6, 2023
kerimdzhanov added a commit that referenced this issue Dec 5, 2023
Allow explicitly specify a list (and the order) of `.env*` files to load using `options.files`.
@kerimdzhanov
Copy link
Owner

kerimdzhanov commented Dec 5, 2023

Heya @timhettler 🙌

Here is a PR: #87. Please take a look when you have a free moment. If everything is good I'll release it as v4.1.0.

@timhettler
Copy link
Author

Thank you for this change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants