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

.env vars overload vars set in environment #1499

Closed
morrislaptop opened this issue Jun 7, 2018 · 3 comments
Closed

.env vars overload vars set in environment #1499

morrislaptop opened this issue Jun 7, 2018 · 3 comments

Comments

@morrislaptop
Copy link
Contributor

morrislaptop commented Jun 7, 2018

Version

3.0.0-beta.15

Reproduction link

https://github.com/morrislaptop/vue-env-issue

Steps to reproduce

  • Step 1: Run yarn serve
  • Step 2: Run VUE_APP_FOO=foorbar yarn serve

Now put "VUE_APP_FOO=bar" in .env.local

  • Step 3: Run yarn serve
  • Step 4: Run VUE_APP_FOO=foorbar yarn serve

What is expected?

I would expect the env vars to be loaded with the following specificity (later overrides earlier)

  • .env
  • .env.local
  • shell environment variables

Results:

  1. VUE_APP_FOO=foo
  2. VUE_APP_FOO=foobar
  3. VUE_APP_FOO=bar
  4. VUE_APP_FOO=foobar

What is actually happening?

The env vars are loading in the following specificity (later overrides earlier)

  • shell environment variables
  • .env
  • .env.local

Results:

  1. VUE_APP_FOO=foo
  2. VUE_APP_FOO=foo
  3. VUE_APP_FOO=bar
  4. VUE_APP_FOO=bar
@LinusBorg
Copy link
Member

LinusBorg commented Jun 7, 2018

These Lines:

Object.keys(config).forEach(key => {
process.env[key] = config[key]
})

should probably look more like this:

  Object.keys(config).forEach(key => {
     // see @akryum's comment
    //  if (!process.env[key]) {
    if (typeof process.env[key] !== undefined) {
      process.env[key] = config[key]
    }
})

Then we would have to switch the order off appliance to

  • .env.mode.local
  • .env.mode
  • .env.local
  • .env

which means switching these calls:

load(basePath)
load(localPath)

...as well as these:

this.loadEnv()
// load mode .env
if (mode) {
this.loadEnv(mode)
}

@Akryum
Copy link
Member

Akryum commented Jun 7, 2018

I would probably do if (typeof process.env[key] === 'undefined') { instead.

@LinusBorg
Copy link
Member

right!

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

No branches or pull requests

3 participants