tem*_*mp_ 35 node.js firebase google-cloud-functions
Firebase的Cloud Functions刚刚发布,我正在按照全新安装的说明进行操作.这是"开始使用"页面.
我已经安装了"npm install -g firebase-tools",我的所有文件都在我的项目中.我正在使用WebStorm 2016.3和Node.JS v6.10.0.
我安装了firebase登录和firebase init函数并进行了设置.我的设置.
我的package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"firebase-admin": "^4.1.2",
"firebase-functions": "^0.5"
},
"private": true
}
Run Code Online (Sandbox Code Playgroud)
前两行代码工作正常.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行这条线时......
admin.initializeApp(functions.config().firebase);
Run Code Online (Sandbox Code Playgroud)
我收到这个错误.
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)
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
小智 53
如果像我一样,在尝试在本地运行函数时遇到此错误,则因为functions.config()
它仅在Cloud Functions运行时中可用.
如果您在部署之前尝试测试功能,请参阅文档的链接,了解如何执行此操作:在本地运行功能.具体来说,这部分是有意义的:
如果您正在使用自定义函数配置变量,请在运行firebase serve之前在项目的functions目录中运行以下命令.
Run Code Online (Sandbox Code Playgroud)firebase functions:config:get > .runtimeconfig.json
但是,如果您使用的是Windows PowerShell,请将以上命令替换为:
Run Code Online (Sandbox Code Playgroud)firebase functions:config:get | ac .runtimeconfig.json
firebase
即使您尝试安装最新版本,看起来您可能仍然拥有旧版本的CLI firebase-tools
.
你可以通过跑步来检查firebase --version
.至少应该这样说3.5.0
.如果没有,你会想npm install -g firebase-tools
再次运行,这应该有希望解决问题.
如果您firebase --version
继续显示错误的版本,则需要检查是否意外安装了多个版本firebase-tools
.
归档时间: |
|
查看次数: |
11389 次 |
最近记录: |