0

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

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
TheFastCat
  • 3,134
  • 4
  • 22
  • 32

2 Answers2

1

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().

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • This solves the issue -- but why? is config() a reserved name in Firebase? Will changing the name of my method from config to something else resolve this workaround? my other methods work without doing this. – TheFastCat Mar 06 '18 at 23:26
  • The CLI isn't intended to be used to invoke arbitrary JavaScript functions defined in your code. It's for invoking Cloud Functions code that your index.js exports via the interface described in the documentation. – Doug Stevenson Mar 06 '18 at 23:31
  • My other Firebase Functions work without doing this. – TheFastCat Mar 06 '18 at 23:31
  • That's because your Cloud Functions are exported, which makes them visible to the code the required your index.js module. Other functions that are *not* exported are *not* visible to the code that required it. They're effectively private. Again, you're trying to use the emulator in a way that wasn't intended. If you wan to unit test some arbitrary code, there are better ways to go about that. – Doug Stevenson Mar 06 '18 at 23:43
0

Are you sure you are on the latest version of firebase-tools? You can update by running 'npm install -g firebase-tools'. You should be on v3.17.4, there was a known bug that was resolved in that version.

laurenzlong
  • 2,169
  • 1
  • 13
  • 13