简体   繁体   English

类型错误:无法读取新 DataSnapshot 中未定义的属性“startsWith”

[英]TypeError: Cannot read property 'startsWith' of undefined at new DataSnapshot

I am trying to write a Cloud Function to listen for Realtime Database triggers with Firebase.我正在尝试编写一个云函数来使用 Firebase 侦听实时数据库触发器。 But I need to listen for my second database instance but it gives me error like this:但是我需要监听我的第二个数据库实例,但它给了我这样的错误:

functions: TypeError: Cannot read property 'startsWith' of undefined at new DataSnapshot it just gives this error when my function is triggered. functions: TypeError: Cannot read property 'startsWith' of undefined at new DataSnapshot它只会在我的函数被触发时出现此错误。

(it works on deployment but not on emulator) (它适用于部署,但不适用于模拟器)

Here is my function:这是我的功能:

exports.checkInteractionCount = functions.database.instance("my-db-name").ref("path/to/data").onUpdate(async (change, context) => {
    //console.log(change);
})

this is just a basic function but it gives error that I shared.这只是一个基本功能,但它给出了我分享的错误。

Here were error occurs:这里发生了错误:

lass DataSnapshot {
    constructor(data, path, // path will be undefined for the database root
    app, instance) {
        this.app = app;
        if (app && app.options.databaseURL.startsWith('http:')) {
            // In this case we're dealing with an emulator
            this.instance = app.options.databaseURL;
        }
.
.
.

我遇到了同样的问题,我通过删除函数文件夹并再次运行 firebase init 来解决它......然后我只是替换了文件并且一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM