0

I am currently working on a project where I have set up dotenv-vault to handle my .env files. One of the environment variables in the .env file is GOOGLE_APPLICATION_CREDENTIALS=/workspaces/project-name/GOOGLE_APPLICATION_CREDENTIALS.json, which points to a service account key file (already added to .gitignore).

The issue I am facing is that when I run the command source .env in my terminal and echo the variable, it displays the correct path. However, when I run any Firebase command, which should recognize the presence of the file and use it for authentication against Google, it fails to authenticate.

Surprisingly, when I manually run the command export GOOGLE_APPLICATION_CREDENTIALS=/workspaces/project-name/GOOGLE_APPLICATION_CREDENTIALS.json, it works as expected. I'm curious to understand why this manual export works while sourcing the .env file does not.

Additionally, I'm using ZSH in my development container with the "dotenv" plugin, but it does not seem to populate the environment variables from the file into the terminal. I'm seeking insights on why this might be happening.

Any help or suggestions would be greatly appreciated.

EzeTeja
  • 1,125
  • 1
  • 13
  • 21
  • 1
    Possibly related: https://stackoverflow.com/a/7411509 (tl;dr: you may need the `export` keyword in the `.env` file). – Gairfowl Jul 09 '23 at 00:53
  • 1
    Also, `.env` is not a standard `zsh` startup file. How does dotenv-vault make the values in the file available to `zsh`? – Gairfowl Jul 09 '23 at 00:55
  • To be honest, I don't know. Based on this: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dotenv I guessed that it loaded the environment variables from the .env file into the terminal. If it is not enough, do you know any other plugin that does this? – EzeTeja Jul 09 '23 at 10:56
  • That plugin probably works as well as any, but those kinds of tools have several links in the chain and therefore many places they can break. Some things to check: `omz`setup in `.zshrc`, the plugin setting and spelling, whether a hook is added to the `chpwd_functions` array. You may be able to add print statements to the `.env` file to ensure it is being invoked. – Gairfowl Jul 11 '23 at 01:23

0 Answers0