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?
The folder structure is
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.
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 fork
ed process so they are available to node-config.