首页 > 解决方案 > 无法从 Android Studio 部署到 Firebase Cloud Functions

问题描述

我最近根据此处的文档更新了新的云功能。

我已经对之前响应我的.onCreate()方法的代码进行了所有更新。但是,现在当我调用 时firebase deploy --only functions,我在 Android Studio 中的终端只是冻结了,我检查了我的 Firebase 控制台中的日志,发现没有执行任何操作。

下面是相关的代码,node.js 和 JavaScript:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.trackVote = 
functions.firestore.document('Polls/{pollId}/responses/{userId}')
.onCreate(change, context => {

       const data = change.after.data();
       const answerSelected = data.answer;

       const answerRef = admin.firestore().doc(`Polls/${event.params.pollId}/answers/${answerSelected}`);
       const voteCountRef = admin.firestore.doc(`Polls/${event.params.pollId}/vote_count`);

        return admin.firestore().runTransaction(t => {
                    return t.get(answerRef)
                        .then(doc => {
                            if (doc.data()) {
                                t.update(answerRef, { vote_count: doc.data().vote_count + 1 });
                            }
                        }
                };
        //do not add to Git
         return admin.firestore().runTransaction(t => {
            return t.get(voteCountRef)
                .then(doc =>){
                    if (doc.data()){
                        t.update(voteCountRef, {vote_count:doc.data().vote_count+1});
                    }
                }
         };

});

编辑:错误终于出现了:

SyntaxError: missing ) after argument list
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
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/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11

标签: javascriptnode.jsfirebasegoogle-cloud-functions

解决方案


推荐阅读