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
firebase emulators:start always ignores .env
file and throws “Attempted to write param-defined key” error
#5219
Comments
.env
file and throws “Attempted to write param-defined key” error..env
file and throws “Attempted to write param-defined key” error
For people who want to workaround with this: Disable
Or downgrade
@inlined After bisecting, I found that this issue was introduced in commit 87e8f0c, which switches After I changed the Not really sure how to fix it as I'm not familiar to Footnotes
|
Hey @Berlioz I think you know this codebase a bit better than me, do you mind taking a look at this? |
Experiencing this exact same issue. Migrated to .env variable from functions.config method. When starting emulators it prompts for default values in the terminal even when a default is in the code. |
@pan93412 your two workarounds result in this error being thrown in the startup process "functions: Failed to load function definition from source: FirebaseError: CEL identity expression '{{ params.MIN_INSTANCES }}' was not resolvable to a param" Did you encounter this? Before trying your workarounds I did manually enter a value when prompted in the terminal but it would at least startup correctly. So I'm not sure what the cause is here. |
I never encountered it, sorry. |
same here |
same problem |
To add here, please see my two linked issues that have been closed as duplicates: #5313 #5314 The current behavior is not in line with the docs. The docs here mention that This not working as the emulators do not load the |
Hey folks sorry for the late response, I've merged #5330 that should fix all of these issues. We'll try to cut a release asap! Thanks for your patience |
Hi @colerogers , thanks for the fix but even after upgrading
Contents of the
So it seems, your fix did unfortunately not solve the issue. And I have another related question: |
It still doesn't work when running command |
I noticed that
|
@oluckyman Please see https://firebase.google.com/docs/functions/config-env#params. Your environment variables are not visible during function definition. @sceee Got a fix for this coming soon. Thanks for reporting. |
@taeold thanks for the fix, now at least the log shows it picks up the file: Unfortunately, when using within function execution code, the values from the Following setup:
Now, having a file const environmentVariable_FunctionsEmulator = defineBoolean('FUNCTIONS_EMULATOR')
export function isRunningInEmulator(): boolean {
console.log(`Process env: ${process.env.FUNCTIONS_EMULATOR}`)
console.log(`defineBoolean: ${environmentVariable_FunctionsEmulator.value()}`)
return environmentVariable_FunctionsEmulator.value() === true
} When calling
even though in the |
Hey @sceee. Do you mind sharing more about what you are trying to do with the emulator? To my knowledge All of the features being used here - params, environment variables, etc - are only relevant to emulated functions. Functions Emulator will make sure functions defined using the Firebase Functions SDK are spun up with runtime environment similar to what you'd see when you deploy your functions to Google Cloud Functions. Script that is run as part of |
Hey @taeold , I am having a lot of automated tests testing the Functions code that are executed using the emulator suite. And for some of these tests, I change some behavior when the functions are executed in the emulator suite compared to when the functions are executed in staging / production.
Then I could just check in the functions code whether I am in the emulator like this: export const isRunningInEmulator = process.env.FUNCTIONS_EMULATOR === 'true' One particular example usecases for having this is testing a function that makes an external API call that I do want to "mock" out when being in the emulator. So when being in the emulator, it just returns true: function someFunction(): boolean {
if (isRunningInEmulator) {
return true
} else {
return makeApiCall()
}
}
Now as Firebase encourages to use The new setup is the one I mentioned in this comment: This is intended to just be a replacement for the |
moved |
@litehacker did something similar to what I described in the last comment work for you? As it is still not working for me. @taeold do you probably have any more insights based on the details I provided in my last comment? |
When I added dotenv, I was able to read the environment variables at startup.
|
I was running into this issue as well, and tried a lot of things in this thread. The final step that helped me was upgrading firebase-tools.
For good measure, I'm also using
Now,
|
I spent a couple of hours on this. In my case, I had env variables starting with Give this author a clap if it helps you!
Reserved env variables: |
Thanks, works good! |
Thank you!! |
[REQUIRED] Environment info
firebase-tools: 11.16.0
Platform: macOS Ventura 13.0
[REQUIRED] Test case
https://github.com/pan93412/firebase-question-221105/tree/373cce9e7093f707198cfa0ff2fbba561c6b167c
[REQUIRED] Steps to reproduce
firebase-functions/params
, see “Test case.”.env*
files – ensure the following.env
file is generated byfirebase-tools
.pnpm serve
to build from TypeScript src and runfirebase emulators:start
firebase-tools
prompts to type myDISCORD_TOKEN
andGUILD
– it is expected..env-[project name]
file, and the function starts correctly.pnpm serve
.4.
and saved in5.
– it is unexpected.4.
and press Enter, it throws the following message:.env
to let it work again.The screencast:
firebase-tools-unexpected-behavior-221106.mp4
[REQUIRED] Expected behavior
.env
file, and not prompt for typing again.[REQUIRED] Actual behavior
keywords:
Attempted to write param-defined key
,Failed to load function definition from source
,environment variable
,.env
,params
The text was updated successfully, but these errors were encountered: