【发布时间】:2017-11-13 00:26:37
【问题描述】:
我使用的是最新版本的 Node,v8.9.1,但在部署以下代码时出现此错误:
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:550
async function deleteQueryBatch(db, query, batchSize, results) {
^^^^^^^^
SyntaxError: Unexpected token function
代码(需要虚拟函数来获取错误):
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const db = admin.firestore()
exports.some = functions.firestore.document('x/{x}').onCreate(event => {
})
function deleteCollectionAndReturnDeletedDocs(db, collectionRef, batchSize) {
return deleteQueryBatch(db, collectionRef.limit(batchSize), batchSize, []);
}
async function deleteQueryBatch(db, query, batchSize, results) {
const snapshot = await query.get();
if (snapshot.size > 0) {
let batch = db.batch();
snapshot.docs.forEach(doc => {
if (doc.exists) {
results.push(doc.data())
};
batch.delete(doc.ref);
});
await batch.commit();
}
if (snapshot.size >= batchSize) {
return deleteQueryBatch(db, query, batchSize, results);
} else {
return results;
}
}
如何部署异步功能?我在 Evennode 上的服务器上没有收到此错误。
【问题讨论】:
标签: node.js firebase google-cloud-functions