Skip to content
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

Functions Emulator does not read parameter configuration (.env files) correctly #5313

Closed
sceee opened this issue Dec 8, 2022 · 1 comment

Comments

@sceee
Copy link
Contributor

sceee commented Dec 8, 2022

[REQUIRED] Environment info

firebase-tools: 11.17.0

Platform: Windows

[REQUIRED] Test case

  • Have an empty .env file:
  • Have a .env.default file:
IS_STAGING=false
  • Have a .env.staging file:
IS_STAGING=true
  • Have .env.local file:
FUNCTIONS_EMULATOR=true

Have the following code in the index.ts that references this parameter's value:

...
initializeApp({
  defineBoolean('IS_STAGING')
    .equals(true)
    .thenElse("stagingbucketname", "prodbucketname")
    .toString(),
})
...

Have some test that calls a Cloud Function.

[REQUIRED] Steps to reproduce

  1. Just "start" the Firebase emulator using firebase emulators:start --import=./testdata/emulatordata --project default
    -> The following warning is emitted indicating it could not load the IS_STAGING environment variable from the .env files:
? Enter a boolean value for IS_STAGING:

[REQUIRED] Expected behavior

Is should read the variable from the .env.default file.

[REQUIRED] Actual behavior

It asks for the value of the IS_STAGING environment variable.
On top of that, after entering the value when prompted, it tries to write it to a new file .env.my-project-id instead of the existing .env.default (where default is the alias).

This causes the following output and prevents the emulator from running:

i  functions: Created new local file .env.my-project-id to store param values. We suggest explicitly adding or excluding this file from version control.
!!  functions: Failed to load function definition from source: FirebaseError: Can't have both dotenv files with projectId (env.my-project-id) and projectAlias (.env.default) as extensions.

It should not write any configuration here as the IS_STAGING is already defined in both the .env.default and .env.staging.

Additionally:
If I now rename the .env.default and env.staging files to .env.my-project-id and .env.my-staging-project-id, it still prompts for the value. If I enter it, it fails to start the emulator as the value is already defined (this relates to/duplicates #5219 ):

? Enter a boolean value for IS_STAGING: false
i  functions: Loaded environment variables from .env, .env.my-project-id.
i  functions: Loaded environment variables from .env, .env.my-project-id.
!!  functions: Failed to load function definition from source: FirebaseError: Attempted to write param-defined key IS_STAGING to .env files, but it was already defined.
@aalej
Copy link
Contributor

aalej commented Dec 9, 2022

This seems to be a duplicate of #5314. That said, I'll close this issue now. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants