-
Notifications
You must be signed in to change notification settings - Fork 938
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
Project-specific .env files aren't loaded when running functions emulator #4239
Comments
I'm seeing this same behavior. I interpreted the documentation the same as you did. Looking at the docs again, it could be interpreted in a way that matches the implementation where they don't intend the project-specific configuration to ever be used in the emulator. That fact isn't super clear, but I think the wording of the section offers a clue: "Deploying multiple sets of environment variables". "Deploying" in this case would suggest they are not talking about the emulator. I'm thinking that now that I understand this, I can make the current implementation work for my purposes. But, I agree that at a minimum the documentation should probably be updated to clarify this fact. |
Thanks for a thorough writeup. I think the documentation is right and the implementation is wrong. We will work on a fix to be shipped in the next release. |
Thanks @taeold. This is maybe another bug/feature request, but I also noticed that .env variables aren't available when the "startup code" is ran, so it's currently not possible to e.g. store the region in an environment variable and use it like so:
The environment variables aren't available to use at the time when Is this something you're aware of/decided not to support? Or should I create a new bug/feature request for it? |
I've had to remove my dynamic exports because of this. It would be nice to have this functionality back |
In my case, when I start the emulator the message below is not even showing:
|
…#4273) Today, Functions Emulator does not load project-specific environment variables. This contradicts the public documentation which states: > When using a local Cloud Functions emulator, you can override environment variables for your project by setting up a .env.local file. Contents of .env.local take precedence over .env and the project-specific .env file. https://firebase.google.com/docs/functions/config-env#emulator_support The patch fixes the bug by making appropriate changes to load project-specific environment variables (either in `.env.projectId` or `.env.projectAlias`) when emulating functions. Fixes #4239
Hi @taeold, could you comment on the above point? |
@taeold Hi. This is still not working for me locally. The variables are loaded from .env if I remove the .env.local file but the variables are not loaded at all if I add a .env.local file. I'm also importing variables from Secrets Manager which is working fine. Is this suppose to be working now? |
Not quite the described issue, but may help those who landed here searching for a related issue. If any key in
Please hide/delete if irrelevant. |
|
This is the old method for environment variables and what I used in previous projects. However, though not directly said in the docs, their language about migrating to the new .env method and how "config" is removed from V2 cloud functions makes me worry that it may be deprecated in the not too distant future. My hope is that this is an oversight as @larrifax mentioned. EDIT: The docs also suggest that if you have V2 cloud functions alongside V1 functions then deploys will fail if using "config()"; |
Why is this closed ? You cannot deploy to |
Same here, my .env or .env.local files are not loaded when I start the emulator |
|
Please refer here for a rationale of the previous, current and future solution. Please note, Remote Config is deprecated and cannot be used when deploying v2 functions. |
Thanks for reopening this. It would be great if this could work as expected. |
IMPORTANT NOTE Please verify that you did not set any variable using a reserved name. If you do that, the emulator will just fail silently upon loading the functions and not load your Some of those reserved names could be "popular", such as "All keys starting with FIREBASE_". |
You're missing the point of the issue at hand. Please refer to firebase/firebase-functions#1084 |
any news on this ? |
Same issue here - how are we supposed to migrate to functions V2 if we can't use |
Just ran into this. Very painful having to deploy my functions just to see if they work, despite having a perfectly good local emulator. You can kind of hack around it by bringing in EDIT |
If you're having problem with process.env in firebase functions this should help |
I had this same problem - removed a
|
Unsure if related, but |
Hi all, thanks for helping us and others diagnose issues with loading environment variables in the functions emulator. Two things:
|
This is still broken @blidd-google , please consider re-opening. Details: #6499 |
Currently facing this issue as well and I believe that this started failing after the creation of several aliases. None of my .env files are being read in the emulator, not even in the body of the function. I worked around the issue by installing the |
At the moment my project alias named env files are not being used, I have |
Same issue here, the deployment is failing due to the code requiring an environment variable to exists. The variable is already defined in the $ firebase deploy --only functions
# ...
# i functions: Loaded environment variables from .env.
# ... Using |
Hi, I need to setup a custom environmental variable so that a private npm package that we include into the firebase/functions can configure itself accordingly however it seems like there is no single way for configuring environmental variables in gen2? |
Hi, here Move the .env* files out of functions directly to the root of your directory, and everything works. In my case, I have 3 .env files: .env, .env.beta, .env.prod
instead of
|
Why this is CLOSED? |
[REQUIRED] Environment info
firebase-tools: 10.2.1
Platform: Ubuntu
[REQUIRED] Test case
The documentation around environment variables using .env-files while using the local functions emulator states the following:
However, when running locally the project-specific .env file isn't even loaded, only the
.env
and.env.local
is.And indeed, the source code doesn't even attempt to load project-specific files when running in an emulator setting:
firebase-tools/src/functions/env.ts
Lines 199 to 206 in 5a8bd4e
According to my interpretation of the documentation linked above, there's a mismatch between the documentation and the implementation, which should be resolved one way or another.
[REQUIRED] Steps to reproduce
.env
,.env.development
and.env.local
file to your project, filling them with different environment variablesfirebase use development
firebase emulators:start --only functions
[REQUIRED] Expected behavior
Functions emulator is started, and logs should show that all relevant
.env*
files are loaded:i functions: Loaded environment variables from .env, .env.development, .env.local.
[REQUIRED] Actual behavior
Functions emulator is started, but logs shows that the project specific .env file isn't loaded (
.env.development
is missing from output):i functions: Loaded environment variables from .env, .env.local.
The text was updated successfully, but these errors were encountered: