I am using the newest version of Node, v8.9.1, but I get this error when deploying the code below:
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
Code (dummy function is needed to get the error):
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;
}
}
How can I deploy the async function? I do not get this error on a server on Evennode.