gpt4 book ai didi

javascript - Firebase 函数 : functions is not defined

转载 作者:太空宇宙 更新时间:2023-11-04 03:20:05 27 4
gpt4 key购买 nike

在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

我得到:

Error: Error occurred while parsing your function triggers. ReferenceError: functions is not defined at Object. (/home/[USERNAME HERE]/functions/index.js:1:87) at Module._compile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32) at tryModuleLoad (module.js:499:12) at Function.Module._load (module.js:491:3) at Module.require (module.js:587:17) at require (internal/module.js:11:18) at /usr/local/nvm/versions/node/v8.9.4/lib/node_modules/firebase-tools/lib/triggerParser.js:21:11 at Object. (/usr/local/nvm/versions/node/v8.9.4/lib/node_modules/firebase-tools/lib/triggerParser.js:75:3)

发生了什么事,如何解决?

最佳答案

作为setup documentation解释说,您需要导入所需的模块并初始化应用程序:

// 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();

关于javascript - Firebase 函数 : functions is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51295561/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com