dotenv-safe icon indicating copy to clipboard operation
dotenv-safe copied to clipboard

dotenv-safe/config does not support configuration options by environment variable; dotenv/config does

Open ccw-morris opened this issue 3 years ago • 0 comments

In the description for dotenv/config, it includes the ability to set dotenv configuration options via env var: https://www.npmjs.com/package/dotenv

DOTENV_CONFIG_<OPTION>=value node -r dotenv/config your_script.js

However, this issue - https://github.com/motdotla/dotenv/issues/423 - explains that only works when

using dotenv/config (usually via preloading)

However, the code for dotenv-safe makes a requires call to dotenv not dotenv/config: https://github.com/rolodato/dotenv-safe/blob/master/index.js#L3 And the code for dotenv-safe/config (https://github.com/rolodato/dotenv-safe/blob/master/config.js) replicates the CLI config (https://github.com/motdotla/dotenv/blob/master/lib/cli-options.js), but not the newer ENV options (https://github.com/motdotla/dotenv/blob/master/lib/env-options.js).

This means that the environment variables (e.g. DOTENV_CONFIG_PATH) are not recognised when using dotenv-safe/config. And unfortunately I cannot use the CLI configuration options because I'm running webpack, which fails if it there is a CLI option that it doesn't recognise.

These are the scripts that I've tried: DOTENV_CONFIG_PATH=../../.env node -r dotenv/config $(yarn bin webpack) - this loads the correct .env file, doesn't perform the safety check, and then runs webpack with the variables from the .env file. DOTENV_CONFIG_PATH=../../.env node -r dotenv-safe/config $(yarn bin webpack) - this does not load the correct .env file and then fails on the safety check due to missing env vars.

For now, I can require dotenv-safe in the entry point to my application instead of using dotenv-safe/config. But, it would be nice to be able to use the newer functionality.

ccw-morris avatar Aug 12 '21 12:08 ccw-morris