简体   繁体   中英

My Firebase Cloud Function fails with Object.value is not a function error?

Why am I getting the following error when I try to fetch the values of my Firebase child nodes under registrationTokens:

Database structure:

"fcmtokens" : {
    "dBQdpR7l1WT2utKVxdX2" : {
      "registrationTokens" : {
        "O": ""c4PSCAUAg5s:Yw95DyVxwElE88LwX7" 
      }
    }
  }

Console output:

TypeError: Object.values is not a function

Part of my deployed function to Firebase Cloud Functions:

return admin.database().ref('/fcmtokens/' + toId + '/registrationTokens').once('value').then((userTok) => {

    const registrationTokens = Object.values(userTok.val());

    console.log('registrationTokens', registrationTokens

Object.values() is a feature new in ECMAScript 2017.

Cloud Functions runs node 6 by default, which only supports ECMAScript 2015 (ES6). So, if you're running that code in the default Cloud Functions runtime, you will get that error (because the function doesn't exist).

node 8 supports ECMAScript 2017, and Cloud Functions allows you to deploy to node 8. So, if you really need to use Object.values(), you should deploy to node 8 instead . Or you can use the lodash equivalent .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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