【问题标题】:What does this error mean when deploying Firebase cloud function部署 Firebase 云功能时出现此错误是什么意思
【发布时间】:2020-01-31 06:48:59
【问题描述】:

我正在尝试部署我的第一个 Firebase Cloud Function,但在部署时出现令人困惑的错误

我已经尝试更新 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 但它是空的。

感谢您的帮助。

【问题讨论】:

    标签: javascript android google-cloud-functions


    【解决方案1】:

    所以我想出了如何让它运行,但我不知道这是否是解决这个问题的“正确”方法:在创建项目时生成的 index.ts 文件中,我必须删除实例化函数的行。如果有人知道为什么这会修复错误或对此问题有任何其他意见,我很乐意听到。

    谢谢

    【讨论】:

      猜你喜欢
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 2021-09-25
      • 2021-01-28
      • 1970-01-01
      • 2021-02-24
      相关资源
      最近更新 更多