简体   繁体   中英

Deploy Firebase functions with node-config

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM