Search code examples
firebasegoogle-cloud-functionsfirebase-cli

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?


Solution

  • 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