Firebase deploy trigger functions with dotenv not working
See original GitHub issue[REQUIRED] Environment info
firebase-tools: 11.0.1
Platform: macOS
[REQUIRED] Test case
I have added a .env file providing some variables:
STORAGE_UPLOAD_BUCKET=mycustombucket
Then i want to use this variable to create a trigger:
functions.storage
.bucket(process.env.STORAGE_UPLOAD_BUCKET)
.object()
.onFinalize(async (object) => {
console.log(process.env.STORAGE_UPLOAD_BUCKET);
//DO STUFF...
});
The problem is that STORAGE_UPLOAD_BUCKET is not defined during the time of deployment, so the trigger gets deployed for the default bucket, not matter the value of STORAGE_UPLOAD_BUCKET. But during runtime of the function it is then set. The same problem exists for other triggers: You cannot use environment variables in firestore trigger paths.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Setting up dotenv in firebase functions - Stack Overflow
Set your variables in the corresponding environment, and then run firebase use dev or firebase use prod before you deploy.
Read more >Configure your environment | Cloud Functions for Firebase
When deploying a function with parameterized configuration variables, the Firebase CLI first attempts to load their values from local .env files.
Read more >Fixing the Firebase Functions Configuration Loading Issues
A quick tutorial to debug and fix issues with environment variables not being loaded in Firebase Functions. Also applies to the local ...
Read more >Using Environment Variables | Cloud Functions Documentation
Runtime environment variables are key/value pairs deployed alongside a function. These variables are scoped to the function and are not visible to other ......
Read more >Firebase functions cannot find module express
Heroku deploy fails with react and next js; Node. 18. ... Issues with node - Error: Cannot find module 'firebase-functions' Ask Question Asked...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We didn’t remove Runtime Config from the discovery phase for reverse compatibility reasons, though it is going away in general (no ETA yet). We don’t populate dotenv files during the discovery phase because our reconciliation between Functions and Extensions requires us to be able to determine the shape of the deployment generically outside the context of the project/environment variables. We’ll do this by capturing dependencies on, for example, the storage bucket as a “parameter”. This parameter will be enforced at deploy time (e.g. while interactive you’ll be prompted for any missing values and in non-interactive mode a deployment will fail). It will be backed by dotenv files in Cloud Functions for Firebase and by the backend server in the case of Firebase Extensions.
Yes, I would recommend checking the status of an environment variable before doing global initialization. So instead of:
change to
We are considering giving a startup callback as well so you can have code that runs only when a new instance is launched in production.