dotenv-module
dotenv-module copied to clipboard
System vars should overwrite dotenv vars
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
Does it work as expected with systemvars: true
?
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??
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).
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.
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?
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 :+1:
+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?
+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.
Any updates here? Seems problematic to not be able to override the .env with system vars.