У меня есть функция Javascript Cloud, как показано ниже, и когда я развертываю Firebase, я получаю ошибку синтаксического анализа. Я жалуюсь на строку const response = await admin.messaging().sendToDevice(tokens, payload);
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.sendFollowerNotification = functions.database.ref('/orders/{order_id}')
.onWrite(async (change, context) => {
// get vars
const order_id = context.params.order_id;
console.log('order_id:', order_id);
const uid = change.after.data().uid;
console.log('uid:', uid);
// get user and send notifications
const docRef = db.collection('users').doc(uid);
const getDoc = docRef.get()
.then(doc => {
const fcmToken = doc.data().fcmToken;
console.log('fcmToken:', fcmToken);
const payload = {
notification: {
title: 'We have received your order!',
body: `Thank you, we have received order ${order_id}`
}
};
const response = await admin.messaging().sendToDevice(tokens, payload);
console.log('response:', response);
});
});
Ошибка:
35:37 error Parsing error: Unexpected token admin
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.