目前,我正在使用firebase-cloud-messaging进行推送通知。仍然支持令牌click_action,但是仍然出现此错误。 我的代码是 ,
cmd(Firebase CLI)上的错误是
notification: {
title: "Notification from" + from_name,
body: from_message,
sound: "default"
click_action: "com.example.tysf_trial"
}
部署时遇到此错误,
43:5 error Parsing error: Unexpected token click_action
? 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\abc\AppData\Roaming\npm-cache\_logs\2019-11-05T19_43_05_08
1Z-debug.log
events.js:187
throw er; // Unhandled 'error' event
^
Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
at notFoundError (C:\Users\abc\AppData\Roaming\npm\node_modules\←[4mfirebase
-tools←[24m\node_modules\←[4mcross-env←[24m\node_modules\←[4mcross-spawn←[24m\li
b\enoent.js:6:26)
at verifyENOENT (C:\Users\abc\AppData\Roaming\npm\node_modules\←[4mfirebase-
tools←[24m\node_modules\←[4mcross-env←[24m\node_modules\←[4mcross-spawn←[24m\lib
\enoent.js:40:16)
at ChildProcess.cp.emit (C:\Users\abc\AppData\Roaming\npm\node_modules\←[4mf
irebase-tools←[24m\node_modules\←[4mcross-env←[24m\node_modules\←[4mcross-spawn←
[24m\lib\enoent.js:27:25)
←[90m at Process.ChildProcess._handle.onexit (internal/child_process.js:272:1
2)←[39m
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:\Users\abc\AppData\Roaming\npm\node_modules\←[4mf
irebase-tools←[24m\node_modules\←[4mcross-env←[24m\node_modules\←[4mcross-spawn←
[24m\lib\enoent.js:30:37)
←[90m at Process.ChildProcess._handle.onexit (internal/child_process.js:272:1
2)←[39m {
code: ←[32m'ENOENT'←[39m,
errno: ←[32m'ENOENT'←[39m,
syscall: ←[32m'spawn npm --prefix "%RESOURCE_DIR%" run lint'←[39m,
path: ←[32m'npm --prefix "%RESOURCE_DIR%" run lint'←[39m,
spawnargs: []
}
答案 0 :(得分:0)
这是我的打孔工作代码,它昨天与我一起工作... ^ _ ^
'use-strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.firestore.document
("NotifyUsers/{user_id}/Notification/{notification_id}")
.onWrite((change, context) => {
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
return admin.firestore().collection("NotifyUsers")
.doc(user_id).collection("Notification").doc(notification_id)
.get().then(queryResult => {
const {from:from_user_id, message:from_message} = queryResult.data();
const from_data = admin.firestore().collection("NotifyUsers")
.doc(from_user_id).get();
const to_data = admin.firestore().collection("NotifyUsers")
.doc(user_id).get();
return Promise.all([from_data, to_data, from_message , from_user_id]);
// added from_message so it's available in the next .then
})
.then(([from_data, to_data, from_message, from_user_id]) => { // added from_message
const from_name = from_data.data().name;
const {name:to_name, token_id} = to_data.data();
console.log("From: " + from_name + " | To : " + to_name +"from:" +from_user_id);
const payload = {
"notification" : {
"title" : "Notification From : " + from_name,
"body" : from_message,
"icon" : 'default',
"click_action": 'return.to.NotificationActivity'
},
"data": {
"from_user_id" : from_user_id,
"message" : from_message
}
};
return admin.messaging().sendToDevice(token_id, payload);
})
.then(result => {
return console.log("Notification Sent");
});
});
答案 1 :(得分:-1)
在sound:
行之后您缺少逗号:
notification: {
title: "Notification from" + from_name,
body: from_message,
sound: "default", // here
click_action: "com.example.tysf_trial"
}