【问题标题】:Cloud Functions for Firebase FCM reference errorCloud Functions for Firebase FCM 参考错误
【发布时间】:2018-06-26 06:09:55
【问题描述】:

错误

ReferenceError: 函数未定义 在对象。 (C:\Users\CROWDE~1\AppData\Local\Temp\fbfn_9612Si4u8URDRCrr\index.js:5:21) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在 C:\Users\crowderia\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:18:11 在对象。 (C:\Users\crowderia\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:32:3)

index.js 文件如下

'use strict'
const funnctions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Notifications/{user_id}/{notification_id}').onWrite(event => {
  const user_id = event.params.user_id;
  const notification_id = event.params.notification_id;
  cosole.log('User id is : ', user_id);
  if (!event.data.val()) {
    return console.log('A Notification has been deleted from the database : ', notification_id);
  }
  const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');
  return deviceToken.then(result => {
    const token_id = result.val();
    const payload = {
      notification: {
        title: "Friend Request",
        body: "You've received a new Friend Request",
        icon: "default",

      }
    };
    return admin.messaging().sendToDevice(token_id, payload).then(response => {
      console.log('this is the notification feature');
    });
  });
});

【问题讨论】:

  • 删除图标后的逗号:"default"

标签: javascript node.js firebase firebase-cloud-messaging google-cloud-functions


【解决方案1】:

第一行有错别字

const function = require('firebase-functions');

函数,而不是函数 :) 所以这一行

functions.database.ref('/Notifications/{user_id...

会工作

【讨论】:

    【解决方案2】:

    cosole.log('User id is : ', user_id); 将其更改为 console.log('User id is : ', user_id); 并将功能更改为函数。

    【讨论】:

      猜你喜欢
      • 2017-08-30
      • 2017-10-05
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 2017-09-09
      • 2017-11-06
      • 2018-08-21
      相关资源
      最近更新 更多