0

I created a firebase function that uses this config library https://www.npmjs.com/package/config. When I run it locally everything works.

When I try to deploy, firebase deploy --only functions the config directory and related files in the functions folder, don't seem to get uploaded. My function fails when it tries to read the config values.

How can I tell firebase to deploy my config directory along with the functions?

Update

The folder structure is

  • functions
    • index.js
    • package.json
    • test
      • index.test.json
    • node_modules
      • ...
    • config
      • default.json

firebase output below

root@fc19e6bca144:/appfiles# firebase deploy --only functions   

=== Deploying to 'familybank'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.

Error: Configuration property "dialogflow.intents.welcome_user" is not defined
    at Config.get (/appfiles/functions/node_modules/config/lib/config.js:203:11)
    at Object.<anonymous> (/appfiles/functions/index.js:39:19)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
    at Module.require (internal/modules/cjs/loader.js:643:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:15:15
    at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:53:3)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)

dialogflow.intents.welcome_user is provided in config/defaults.json, so I assume it didn't upload.

Community
  • 1
  • 1
Daniel Watrous
  • 3,467
  • 2
  • 36
  • 48
  • 2
    Can you update your question to show what the folder hierarchy for your project is, including where the configuration files are, and how you're using the library to load the configuration files? – Prisoner Nov 28 '18 at 15:23
  • Can you include the error you get, when the function fails to depoy? – Chadd Nov 28 '18 at 20:26
  • I discovered that the error occurs here https://github.com/firebase/firebase-tools/blob/78f11b62ab658a5a59b291daad7ea5ee08b2bc34/src/triggerParser.js#L21. Since firebase is running below the functions directory, node-config can't find the configuration directory. I can make a deployment work if I copy my config directory to where I run the firebase command. I also tried setting the environment variable NODE_CONFIG_DIR, but it had no effect. – Daniel Watrous Nov 29 '18 at 14:24
  • I realized that when I run firebase commands, overall environment variables are ignored. I attempted to `firebase functions:config:set NODE_CONFIG_DIR="./functions/config"`, but I get an error about it being upper case. – Daniel Watrous Nov 29 '18 at 14:47

1 Answers1

0

Most of the details are in this issue: https://github.com/firebase/firebase-tools/issues/1046 (and corresponding pull request).

In this case, node-config was looking for the config directory off the directory where the script was originally run, rather than relative to the script that was being imported. While node-config does provide a way to override this with an environment variable, https://github.com/lorenwest/node-config/wiki/Environment-Variables, the firebase CLI dropped the environment variables, so it still couldn't find it.

The fix, as seen in the pull request, is to capture the current environment variables and pass them to the forked process so they are available to node-config.

Daniel Watrous
  • 3,467
  • 2
  • 36
  • 48
  • While I wait for my PR to get fixed, I am using this docker image https://hub.docker.com/r/dwatrous/firebase-tools, tag `6.1.1.mod_env` which has the updated file. – Daniel Watrous Nov 29 '18 at 22:56