Firebase Unhandled error RangeError: Maximum call stack size exceeded

前端 未结 3 538
青春惊慌失措
青春惊慌失措 2020-12-07 02:12

I\'m calling a Firebase callable function, and returning the promise as specifed by Firebase, but I get this error:

Unhandled error RangeError: Maximum call stack si

3条回答
  •  死守一世寂寞
    2020-12-07 03:06

    The problem is similar to the one described here. You're returning a complex object generated by the Firebase API called a DocumentSnapshot. A snapshot it not itself raw JSON data to return to the client, and it contains circular references to other objects. Cloud Functions is stuck trying to serialize all of these objects. Instead, just return the raw JavaScript object of the data at the location of interest by calling val() on the snapshot:

    return database
        .ref('/products/' + product)
        .orderByKey()
        .endAt(ts)
        .limitToLast(1)
        .once('value')             // once() returns a promise containing a snapshost
        .then(snapshot => {
            return snapshot.val()  // this is the raw JS object
        })
    

    You generally don't use both the returned promise and the callback in the same call. It's easier to just use the promise.

提交回复
热议问题