Я пытаюсь развернуть свою первую облачную функцию Firebase, но при развертывании я получаю сбивающую с толку ошибку
Я пытался обновить npm, но все равно получаю ту же ошибку
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.firestore.document("posts/{userID}/userPosts/{postDate}").onWrite(event => {
const userEmail = event.params.userEmail;
const notificationId = event.params.notificationId;
return admin.firestore().collection("notifications").doc(userEmail).collection("userNotifications").doc(notificationId).get().then(queryResult => {
const senderUserEmail = queryResult.data().senderUserEmail;
const notificationMessage = queryResult.data().notificationMessage;
const fromUser = admin.firestore().collection("users").doc(senderUserEmail).get();
const toUser = admin.firestore().collection("users").doc(userEmail).get();
return Promise.all([fromUser, toUser]).then(result => {
const fromUserName = result[0].data().userName;
const toUserName = result[1].data().userName;
const tokenId = result[1].data().tokenId;
const notificationContent = {
notification: {
title: fromUserName + " is shopping",
body: notificationMessage,
icon: "default"
}
};
return admin.messaging().sendToDevice(tokenId, notificationContent).then(result => {
console.log("Notification sent!");
//admin.firestore().collection("notifications").doc(userEmail).collection("userNotifications").doc(notificationId).delete();
});
});
});
});
Я ожидаю, чтоФункция будет опубликована и вернет URL, который я могу использовать в своем коде. Однако я получаю эту ошибку:
src/index.ts:1:1 - error TS6133: 'functions' is declared but its value is never read.
1 import * as functions from 'firebase-functions';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/David/.npm/_logs/2019-10-02T00_37_40_011Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
Я посмотрел в /Users/David/.npm/_logs/2019-10-02T00_37_40_011Z-debug.log, но он был пустым.
СпасибоВам за любую помощь.