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

New .env-based configuration is not available on functions start in emulator #4361

Closed
uvesten opened this issue Mar 25, 2022 · 3 comments
Closed

Comments

@uvesten
Copy link

uvesten commented Mar 25, 2022

I've spent quite a bit of time to move from the old functions.config() system to the new .env-file based config for better developer ergonomics. I'm very, very disappointed that this "feature" was released at all in its current state, since it's a major regression compared to functions.config().

That an environment variable needs to be set in the environment before starting to execute an arbitrary function, that should be obvious. The config values might be available inside runWith(), .onCall() etc, but that's not enough. Please fix this or release a new major version, removing support until you can get it right.

My case:

Using a config variable to decide which region to deploy functions to fails, since the .env-based config is not available on function deploy.

Example:

export const copy = region(process.env.DEPLOY_REGION)
  .runWith()
  .https.onCall(

breaks, because the environment variable does not exist... (It's set correctly in the .env file)

export const copy = region(functions.config().deploy.region)
  .runWith()
  .https.onCall(

Works well.

It's not OK to release a new feature in this state... Please fix or un-release it asap

(Reported to both here and in firebase/firebase-functions#1065 because I don't know which project is responsible for this change)

@DibyodyutiMondal
Copy link

DibyodyutiMondal commented Mar 25, 2022

While they are working on a change, I discovered the two places where we can insert our required env variables, both for the emulator, and deployments.

I dove into the node_modules and changed the code at the locations in the images below. All it does is add the NODE_OPTIONS environment variable. The alternative is to append .js and /index.js to imports as necessary.
(this is specific in my case - you can insert your own variables here as required)

And it works like a charm with nothing more needed.

I have not been able to deploy this on functions v2, but I think that's because of some other issue, not this.

EDIT: This method is of course not scalable for large teams or applicable in a ci environment

(the location of the file I am editing is visible in the left sidebar)

deploy-patch
emulator-patch

@taeold
Copy link
Contributor

taeold commented Mar 25, 2022

Other issues that touches on this problem:

firebase/firebase-functions#1058
firebase/firebase-functions#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 (firebase/firebase-functions#1044) as our single source of truth. Let's continue our discussion there.

@inlined
Copy link
Member

inlined commented Apr 25, 2022

See firebase/firebase-functions#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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants