Search code examples
firebasegoogle-cloud-functionsfirebase-cli

Error invoking firebase function referencing local configuration variables from Firebase Functions Shell


This is a continuation of troubleshooting this problem and a separate issue related to implementing a suggested solution.

I am attempting to consume Firebase function configuration from a locally-served environment as outlined here but I get an unexpected error.

  1. I create a ".runtimeconfig.json" file within my functions directory containing this:

{ "auth": { "clientid": MY_CLIENT_ID, "signoutreturnto": SOME_URL, "responsetype": SOME_URL, "redirecturi": SOME_OTHER_URL, "scope": SOME_OTHER_STRING, "domain": SOME_DOMAIN } }

  1. I execute the following commands from the firebase CLI (within the functions directory):

    • firebase functions:config:get > .runtimeconfig.json
    • firebase experimental:functions:shell
  2. I execute my config function via the cli:

    config()

  3. I get the following error output in the console:

config()

TypeError: config is not a function
    at repl:1:1
    at ContextifyScript.Script.runInContext (vm.js:32:29)
    at REPLServer.defaultEval (repl.js:341:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:96:13)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:241:10)
    at REPLServer.Interface._line (readline.js:590:8)

my other functions, bigben & firebaseConfig execute as expected from the CLI


Solution

  • If you want to see your functions config at the the CLI emulator prompt, you should run the emulator command from your functions directory:

    $ cd functions
    $ firebase experimental:functions:shell
    

    Then, at the firebase prompt, you can access your config like this:

    firebase> const functions = require('firebase-functions')
    firebase> functions.config()
    

    That should print your config. Normally you don't need to do something like this - you would instead just read the config from inside the emulated function using functions.config().