我正在尝试使用以下代码设置一个简单的Google云功能:
index.js:
var functions = require('firebase-functions');
exports.updateLastMessage = functions.database.ref("/messages/{chatID}/{messageID}").onWrite(event => {
console.log("New Message received")
})
package.json:
{
"name": "updateLastMessage",
"version": "0.0.2",
"dependencies": {
"firebase-functions": "^0.5.1",
"actions-on-google": "^1.0.7",
"firebase-admin": "^4.0.5"
}
}
当我尝试部署它时,我会收到以下错误:
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/user_code/node_modules/firebase-functions/lib/config.js:51:15)
at Object.config (/user_code/node_modules/firebase-functions/lib/config.js:29:9)
at Object.ref (/user_code/node_modules/firebase-functions/lib/providers/database.js:58:31)
at Object.<anonymous> (/user_code/index.js:3:48)
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.require (module.js:497:17)
它告诉我更新Firebase CLI,尽管我什至不使用它们,但我正在使用内联编辑器。我该怎么办?
我弄清楚了如何解决此错误。我已经从Firebase CLI部署了一些云功能。当我尝试从Webinterface创建一个新的时,错误会引发。显然,您只能使云功能从相同类型的CLI一起工作,您不能将它们结合起来。要解决错误,我不得不使用控制台重新部署它们。