Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access of configuration variable in Cloud Functions Firebase CLI local emulator failed

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?

like image 608
Leem Avatar asked Jan 28 '18 20:01

Leem


People also ask

How do I turn off Firebase emulator?

Double tap CTRL-C (hold down CTRL and double tap C) in the terminal running the emulator when you want to shut down the emulator and clear all the ports and processes.


1 Answers

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
like image 132
Doug Stevenson Avatar answered Oct 01 '22 21:10

Doug Stevenson