dotenv-org / dotenv-vault

sync .env files—from the creator of `dotenv`.
https://www.dotenv.org
MIT License
1.11k stars 32 forks source link

NX monorepo support | You set DOTENV_KEY but you are missing a .env.vault file at .local.env.vault. Did you forget to build it? #335

Open Husamui opened 5 months ago

Husamui commented 5 months ago

we using NX monorepo for our projects.

Steps:

  1. We placed the .env.vault and env.keys files at the root directory of the nx monorepo.
  2. Run export DOTENV_KEY='dotenv:xxxxx in the command line before serving the app.
  3. calling require('dotenv').config(); in rootDirectory/apps/app_name/src/main.ts.

we got the following warnings in the console when serving the app even though the app server correctly and include the env variables (I believe because .env loading the env variables from step 2)

You set DOTENV_KEY but you are missing a .env.vault file at .local.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][INFO] Loading env from encrypted .env.vault
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .local.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .env.local.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at apps/api/.env.serve.development.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at apps/api/.env.development.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at apps/api/.serve.development.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at apps/api/.development.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at apps/api/.env.serve.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at apps/api/.serve.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at apps/api/.env.local.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at apps/api/.local.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][INFO] Loading env from encrypted .env.vault
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .env.serve.development.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .env.development.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .serve.development.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .development.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .env.serve.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .serve.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .local.env.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][WARN] You set DOTENV_KEY but you are missing a .env.vault file at .env.local.vault. Did you forget to build it?
[ NX] [dotenv@16.3.2][INFO] Loading env from encrypted .env.vault

any suggests?

validkeys commented 5 months ago

@Husamui try also setting an env variable DOTENV_CONFIG_PATH=path/to/.env.vault

then update your dotenv.config to use that path in its options

validkeys commented 5 months ago

@Husamui nevermind -- that was bad advice -- trying to sort through the same issue myself

motdotla commented 5 months ago

@Husamui and @validkeys - dotenv-vault is possible to get going with monorepos but it's a bit awkward.

you need a .env.vaut and DOTENV_KEY per sub project under you monorepo

we have a better answer to monorepos with dotenvx. it has support for doing things like:

dotenvx encrypt
dotenvx encrypt apps/backend
dotenvx encrypt apps/frontend

so that you can have vaults per project in your monorepo. it's a much better experience.

but caveat: the hub (team) features of dotenvx are not comparable to dotenv-vault yet.

summary: once dotenvx's team features mature over the next 6 months, i would recommend choosing it over dotenv-vault.