firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

.env{,.local,.project} file is silently not loaded in emulators (for restricted var)

Open jacobsandlund opened this issue 3 years ago • 3 comments

[REQUIRED] Environment info

**firebase-tools: 11.1.0 **

Platform: macOS

[REQUIRED] Test case

A simple http function which prints out the process.env in a get handler for any path. A .env file which sets a restricted environment variable (say FIREBASE_CONFIG).

[REQUIRED] Steps to reproduce

Start emulators. Hit any route to invoke the function.

[REQUIRED] Expected behavior

There should be some indication that the .env file was at least attempted to be loaded, and why it failed to load. Ideally this would actually occur when the emulators are spun up, and not just when the functions are invoked (mirroring how a deploy to a real firebase environment works).

[REQUIRED] Actual behavior

Firebase emulator seems to be ignoring the .env file. It silently discards it because it has restricted environment variables in there. This makes it really tricky to see the issue. In fact, this issue was at first me thinking that loading environment variables simply didn't work.

jacobsandlund avatar Aug 17 '22 00:08 jacobsandlund

See this comment: https://github.com/firebase/firebase-tools/issues/4239#issuecomment-1065412510

jacobsandlund avatar Aug 17 '22 00:08 jacobsandlund

Ah, from this Stack Overflow post, it might be because one of my environment variables starts with FIREBASE_. https://stackoverflow.com/q/71250286

There is no debug log or output that I see that gives any indication of this when running the emulators, so to me it just looks like it is silently failing.

jacobsandlund avatar Aug 17 '22 01:08 jacobsandlund

We are experiencing this too, no console output mentioning the environment, using the latest firebase-admin and firebase-tools (11.0.1).

I started tracing backwards through FunctionsEmulator::startRuntime but don't have time to investigate too deeply right now, but wanted to share that this indeed is an ongoing problem.

Edit: It looks like the .env files are now loaded, only upon function invocation, but this was definitely not working correctly at one point. If it reproduces I'll add some details.

brianmhunt avatar Sep 10 '22 13:09 brianmhunt

Hey folks sorry for the late response on this issue. We made quite a few changes to the emulator in the past couple months and my testing shows that this issue has been fixed. I'm going to close this out now, feel free to open a new issue if this pops back up. Thanks

colerogers avatar Dec 15 '22 16:12 colerogers