8

I am using Firebase Functions. I set a environment variable by command:

firebase functions:config:set my.token="abcde"

I verified it by command:

firebase functions:config:get

which returns me:

{
  "my": {
    "token": "abcde"
  }
}

in my index.js , I try to get the set token by:

const tok = functions.config().my.token

I would like to test my functions locally instructed by this document, so I run command:

firebase serve --only functions

But it gives me error:

Error from emulator. FirebaseError: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'token' of undefined

Why I can't access the token I set in environment variable of Firebase?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Leem
  • 17,220
  • 36
  • 109
  • 159

1 Answers1

15

This was a bug in the Firebase CLI that was fixed in version 3.17.4. Please update your firebase-tools module:

npm install -g firebase-tools

Also, don't forget to follow the instructions in the documentation and copy your configs to a local file before running the emulator:

cd functions
firebase functions:config:get > .runtimeconfig.json
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 1
    Did you remember to create `.runtimeconfig.json` as suggested in the documentation you pointed to? – Doug Stevenson Jan 28 '18 at 21:20
  • Thanks! That works! BTW, do you know do I need to run the command to copy to local file every time I update the configuration settings? – Leem Jan 28 '18 at 22:24
  • If you want to change your config, yes, you have to recreate the file with those changes for local emulation. – Doug Stevenson Jan 28 '18 at 22:32
  • 1
    Perhaps this answer is outdated, but [the instructions](https://firebase.google.com/docs/functions/local-emulator) do not mention a `.runtimeconfig.json` file. – John Jun 30 '19 at 21:00
  • It's difficult to search up this `.runtimeconfig.json` stuff, even when you know what you are looking for. Eventually found this answer again. – Sam Watkins May 13 '21 at 05:24