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

Unable to use .env variable in functions for database.instance() #1058

Closed
danielluca opened this issue Mar 15, 2022 · 3 comments
Closed

Unable to use .env variable in functions for database.instance() #1058

danielluca opened this issue Mar 15, 2022 · 3 comments

Comments

@danielluca
Copy link

danielluca commented Mar 15, 2022

Version info

node: 16.14.0

firebase-functions: 3.18.1

firebase-tools: 10.2.2

firebase-admin: 10.0.2

Test case

const myFunction = functions
  .runWith({
    vpcConnector: 'static-vpc-connector',
    vpcConnectorEgressSettings: 'ALL_TRAFFIC',
  })
  .region('europe-west3')
  .database
  .instance(process.env.MY_INSTANCE)
  .ref('/some/{ref}')
  .onCreate(async (snapshot, context) => {}

Expected behavior

Function should use the .env variable set in .env file.

Actual behavior

If I set the instance without a .env variable, the function can be deployed.
If I set the instance with a .env, I get an error.

Were you able to successfully deploy your functions?

i  functions: cleaning up build files...
Error: There was an error deploying functions
@google-oss-bot
Copy link
Collaborator

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@taeold
Copy link
Contributor

taeold commented Mar 25, 2022

Other issues that touches on this problem:

firebase/firebase-tools#4361
#1044

Pasting a response I posted in another issue:

As both of you have already found out, we are intentionally not including user-defined environment variables when parsing your source code to discover your functions. This limits their use when compared to functions config.

We are preparing something new that digs into exactly this problem -stay tuned. Until then, I'd suggest that you continue to rely on functions config if need environment-aware logic when deploying your functions.

Since this is a common point of confusion, I'm going to try to consolidate our response in a single issue. Arbitrary going to pick the earliest reported issue (#1044) as our single source of truth. Let's continue our discussion there.

@taeold taeold closed this as completed Mar 25, 2022
@inlined
Copy link
Member

inlined commented Apr 25, 2022

See #1084 for our plans around this area.

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

4 participants