-
-
Notifications
You must be signed in to change notification settings - Fork 862
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
Impossible to set options in some cases #145
Comments
just so we're on the same page, your primary concern is a clean log with no output from if you're using babel and gulp, I'm willing to bet you're using a newer version of node that supports preloading modules. that allows you to remove imports and requires of dotenv from your source code and is my personal recommendation on how to use dotenv in newer projects. babel and gulp both support preloading ( The configuration options you've referenced such as |
Oh wow I thought it actually errored the process, didn't realise it just did a console.error. I think my process was quitting unexpectedly and I assumed it was to do with the error printed by dotenv. Must have been something else. I might PR something to help with cleaner output in this case at some point, but no need to keep this open. Sorry for my confusion :) |
thanks @callumlocke for the feedback |
Personally I think
silent: true
would be a much saner default. I know this was discussed before in #111 and rejected. I guess I will just have to set the option manually, so I can use dotenv in code that might get built in CI where there's no .env file.However, there is no obvious way to use dotenv with non-default options in the following scenario:
import
statement to load modules, andgulp
which will choke ondotenv_config_silent=true
.Example
gulpfile.babel.js
:The problem is the first line will fail on CI where you've got no
.env
. And you can't change your CI build command togulp build dotenv_config_silent=true
because it will error with "Task 'dotenv_config_silent=true' is not in your gulpfile" (btw, why doesn't dotenv follow the convention of prefixing the argument with--
?).You could try doing
import dotenv from 'dotenv'; dotenv.config({silent: true})
, but that doesn't work either, because ES2015 imports are hoisted and executed before all other code, i.e. the call to.config()
won't happen until after other modules are executed, regardless of what order the lines are in. Therefore if another module (e.g../foo.js
in the above example) expects environment variables to have been set before it runs, it will fail. You can't even work around this by doingrequire('dotenv').config({silent: false})
at the very top of the file, because imports still get hoisted and executed first.The only workarounds I can think of are messy/ugly:
require('dotenv').config({silent: false}); require('./real-gulpfile.js');
.env
file before running each build, just to obviate the need for silent:trueA possible solution would be to add
config-silent.js
, which would be likeconfig.js
but with silent:true as a default. Then people could doimport 'dotenv/config-silent';
.The text was updated successfully, but these errors were encountered: