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

System vars should overwrite dotenv vars #46

Open
z0w13 opened this issue Oct 15, 2019 · 9 comments
Open

System vars should overwrite dotenv vars #46

z0w13 opened this issue Oct 15, 2019 · 9 comments

Comments

@z0w13
Copy link

z0w13 commented Oct 15, 2019

What problem does this feature solve?

In most places where dotenv is used system env vars override the dotenv vars, however dotenv-module does the exact opposite, swapping this around would give the expected result when using systemvars: true

This feature request is available on Nuxt community (#c28)
@ghost ghost added the cmty:feature-request label Oct 15, 2019
@avxkim
Copy link

avxkim commented Nov 5, 2019

Does it work as expected with systemvars: true?

@avxkim
Copy link

avxkim commented Nov 5, 2019

Just tested now in nuxt 2.10, nuxt.config.ts:

  modules: [
    ['@nuxtjs/dotenv', { systemvars: true }]
  ],

It has no effect, i'm setting env variables in a compose file, inside a container they are set, but inside my nuxt app they don't work. So as workaround we have to upload our .env file??

@mmorainville
Copy link

Same here, even with systemvars: true the system variables (from Heroku in my case) are not taken into account. So when I deploy to Heroku (git push heroku master) as my .env file is gitignored, and my env var from Heroku are not used, the Nuxt production build is not using them (they are undefined when using process.env to access them).

@mmorainville
Copy link

mmorainville commented Nov 12, 2019

After looking at the source code, it might be because of the return here:

try {
    accessSync(envFilePath, constants.R_OK)
  } catch (err) {
    logger.warn(`No \`${options.filename}\` file found in \`${options.path}\`.`)
    return
  }

Which prevents if (options.systemvars) block to be executed.

@mmorainville
Copy link

mmorainville commented Nov 13, 2019

Sorry for spamming but I also just noticed that if you set your system variables in the env: {} property of your nuxt.config.js file, the system variables ARE taken into account even without an .env file being there.
So this may be a workaround for this issue, or maybe it even is the expected behavior?

@superbiche
Copy link

superbiche commented Nov 26, 2019

Also experiencing this issue, trying to understand why my env variables were working in development - I use a .env file with docker compose - but not in review - Docker build with --build-arg, ARG + ENV before build.

My workaround is to RUN touch .env just before running yarn build so the module stops complaining. And my variables are present in my build 👍

@hartmut-co-uk
Copy link

+1 for this feature request - just as originally raised by @z0w13
(I'd almost argue this is a bug..)

Example: https://codesandbox.io/s/fervent-fire-o6dcu
see package.json modified

  "scripts": {
    "dev": "MINIMAL=1 CSB=1 TEST2=TEST2_OVERRIDE TEST3=TEST3 nuxt",

Expected:
(both server/client console.log)

/home | fetch() | from server
/home | fetch() | process.env.TEST1 TEST1
/home | fetch() | context.env.TEST1 TEST1
/home | fetch() | process.env.TEST2 TEST2_OVERRIDE
/home | fetch() | context.env.TEST2 TEST2_OVERRIDE
/home | fetch() | process.env.TEST3 TEST3
/home | fetch() | context.env.TEST3 TEST3

Actual:
(both server/client console.log)

/home | fetch() | from server
/home | fetch() | process.env.TEST1 TEST1
/home | fetch() | context.env.TEST1 TEST1
/home | fetch() | process.env.TEST2 TEST2
/home | fetch() | context.env.TEST2 TEST2
/home | fetch() | process.env.TEST3 TEST3
/home | fetch() | context.env.TEST3 TEST3

Would a PR be accepted?

@stuft2
Copy link

stuft2 commented Aug 11, 2020

+1 I think this bug report and this "feature-request" are talking about the same issue. The problem is that when deploying an application, the environment variables are ignored since there isn't a .env file in the deployment like there is locally. Correct me if I'm wrong.

@atinux atinux added the help wanted label Dec 16, 2020 — with Volta.net
@marr
Copy link

marr commented Jul 14, 2022

Any updates here? Seems problematic to not be able to override the .env with system vars.

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

8 participants