在本地运行 Cloud Functions 会出现错误“functions.config() 不可用"; [英] Running Cloud Functions locally gives error "functions.config() is not available"

查看:12
本文介绍了在本地运行 Cloud Functions 会出现错误“functions.config() 不可用";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cloud Functions for Firebase 刚刚发布,我正在按照说明进行全新安装.

我的 package.json

<代码> {名称":功能","description": "Firebase 的云功能",依赖":{"firebase-admin": "^4.1.2",firebase 功能":^0.5"},私人":真}

前两行代码有效.

 const functions = require('firebase-functions');const admin = require('firebase-admin');

但是当我尝试运行这条线时......

 admin.initializeApp(functions.config().firebase);

我收到此错误.

 错误:functions.config() 不可用.请使用最新版本的 Firebase CLI 部署此功能.在初始化(/Users/.../functions/node_modules/firebase-functions/lib/config.js:46:19)在 Object.config (/Users/.../functions/node_modules/firebase-functions/lib/config.js:29:9)在对象.<匿名>(/Users/.../functions/index.js:11:31)在 Module._compile (module.js:570:32)在 Object.Module._extensions..js (module.js:579:10)在 Module.load (module.js:487:32)在 tryModuleLoad (module.js:446:12)在 Function.Module._load (module.js:438:3)在 Module.runMain (module.js:604:10)运行时(bootstrap_node.js:394:7)

我在这里遗漏了什么?

解决方案

如果你像我一样在本地运行函数时遇到这个错误,那是因为 functions.config() 只是在 Cloud Functions 运行时中可用.

如果您在部署之前尝试测试您的功能,以下是有关如何测试的文档的链接:在本地运行函数.具体来说,这部分很有趣:

<块引用>

如果您使用自定义函数配置变量,请在运行 firebase serve 之前在项目的函数目录中运行以下命令.

firebase 函数:config:get >.runtimeconfig.json

但是,如果您使用的是 Windows PowerShell,请将上述命令替换为:

firebase 函数:config:get |交流 .runtimeconfig.json

Cloud Functions for Firebase was just recently released and I am following the instructions on a fresh install. Here is the "Get Started" page.

I have installed "npm install -g firebase-tools" and all my files are in my project. I am using WebStorm 2016.3 and Node.JS v6.10.0.

I have the firebase login and firebase init functions installed and set up as well. My set up.

My package.json

 {
   "name": "functions",
   "description": "Cloud Functions for Firebase",
    "dependencies": {
     "firebase-admin": "^4.1.2",
     "firebase-functions": "^0.5"
   },
    "private": true
 }

These first two lines of code work.

  const functions = require('firebase-functions');
  const admin = require('firebase-admin');

But then when I try to run this line...

  admin.initializeApp(functions.config().firebase);

I get this error.

 Error: functions.config() is not available. Please use the latest version of the Firebase CLI to deploy this function.
   at init (/Users/.../functions/node_modules/firebase-functions/lib/config.js:46:19)
   at Object.config (/Users/.../functions/node_modules/firebase-functions/lib/config.js:29:9)
   at Object.<anonymous> (/Users/.../functions/index.js:11:31)
   at Module._compile (module.js:570:32)
   at Object.Module._extensions..js (module.js:579:10)
   at Module.load (module.js:487:32)
   at tryModuleLoad (module.js:446:12)
   at Function.Module._load (module.js:438:3)
   at Module.runMain (module.js:604:10)
   at run (bootstrap_node.js:394:7)

What am I missing here?

解决方案

If, like me, you got this error while trying to run your functions locally then it's because functions.config() is only available within the Cloud Functions runtime.

If you are trying to test your functions before you deploy, here is the link to the documentation on how to do so: run functions locally. Specifically, this part is of interest:

If you're using custom functions configuration variables, run the following command in the functions directory of your project before running firebase serve.

firebase functions:config:get > .runtimeconfig.json

However, if you're using Windows PowerShell, replace the above command with:

firebase functions:config:get | ac .runtimeconfig.json

这篇关于在本地运行 Cloud Functions 会出现错误“functions.config() 不可用";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆