阅读背景:

'functions.config()不可用“使用Node.JS使用Cloudbase for Firebase

来源:互联网 

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

Firebase的云功能最近刚刚发布,我按照新安装的说明进行操作。这是“开始使用”页面。

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.

我已经安装了“npm install -g firebase-tools”,我的所有文件都在我的项目中。我使用的是WebStorm 2016.3和Node.JS v6.10.0。

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

我安装了firebase登录和firebase init函数并进行了设置。我的成立。

My package.json

我的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?

我在这里想念的是什么?

3 个解决方案

#1


25  

If you are like me and got this error trying to run your functions locally then you are getting this error 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: https://firebase.google.com/docs/functions/unit-testing#mocking_database_writes

如果您像我一样并且尝试在本地运行您的函数时遇到此错误,那么您将收到此错误,因为functions.config()仅在Cloud Functions运行时中可用。如果您在部署之前尝试测试功能,请参阅以下文档的链接:https://firebase.google.com/docs/functions/unit-testing#mocking_database_writes

#2


6  

That does look like you might still have an old version of the firebase CLI, even though you tried to install the newest firebase-tools.

即使您尝试安装最新的firebase-tools,看起来您可能仍然拥有旧版本的firebase CLI。

You can check by running firebase --version. That should say at least 3.5.0. If it doesn't, you'll want to run npm install -g firebase-tools again, which should hopefully fix things.

您可以通过运行firebase --version来检查。应该说至少3.5.0。如果没有,你将再次运行npm install -g firebase-tools,这有望解决问题。

If your firebase --version continues to show the wrong version, you'll want to check if you accidentally have multiple versions of firebase-tools installed.

如果您的firebase --version继续显示错误的版本,您将需要检查是否意外安装了多个版本的firebase-tools。

#3


2  

I was running firebase deploy from the wrong dir. Hopefully this will save someone some time.

我从错误的目录运行firebase部署。希望这会节省一些时间。


分享到: