javascript - Firebase 函数:未定义函数
问题描述
在 index.js 中,我有:
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original').onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const original = snapshot.val();
console.log('Uppercasing', context.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return snapshot.ref.parent.child('uppercase').set(uppercase);
});
我从字面上复制粘贴了以下代码: https ://firebase.google.com/docs/functions/get-started
不知何故,当我部署使用
firebase deploy --only functions
我得到:
错误:解析函数触发器时出错。ReferenceError:函数未在 Object 中定义。(/home/[USERNAME HERE]/functions/index.js:1:87) 在 Module._compile (module.js:643:30) 在 Object.Module._extensions..js (module.js:654:10)在 Module.load (module.js:556:32) 在 tryModuleLoad (module.js:499:12) 在 Function.Module._load (module.js:491:3) 在 Module.require (module.js:587: 17) 在 /usr/local/nvm/versions/node/v8.9.4/lib/node_modules/firebase-tools/lib/triggerParser.js:21:11 在 Object 的 require (internal/module.js:11:18) . (/usr/local/nvm/versions/node/v8.9.4/lib/node_modules/firebase-tools/lib/triggerParser.js:75:3)
发生了什么事,我该如何解决?
解决方案
正如设置文档所解释的,您需要导入所需的模块并初始化应用程序:
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp();
推荐阅读
- reactjs - 只有一个表单使用反应钩子正确提交
- javascript - Ajax - 如何使用 Ajax/jquery 将选项添加到数据列表中
- javascript - 在不加载活动选项卡的情况下运行内容脚本
- python - 需要帮助来理解错误:不可散列类型“设置”意味着错误,如何更改为不可变
- c - C中的增量问题(指针)
- c# - 如何从 Azure 容器中的 blob 中获取所有 URL 的列表?
- c# - Ucommerce (Umbraco) 购物篮在切换上下文时删除订单行
- elasticsearch - Elasticsearch 德语词干分析器不做复数
- jmeter - 如何在 Jmeter 的 Beanshell 中拆分字符串
- mybatis - Mybatis and Spring Boot 2.5