Open leenorshn opened 6 years ago
Modify in firebase.json from "npm --prefix $RESOURCE_DIR run lint" to "npm --prefix %RESOURCE_DIR% run lint"
It Worked For Me.
On Firebase init step, when it asked "Do you want to use ESLint to catch probable bugs and enforce style?" You just say no It should solve your problem
Got error in log :
My index.js is here
`'use strict'
const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/notification/{user_id}/{notification_id}').onWrite(event => {
const user_id = event.params.user_id; const notification = event.params.notification;
console.log("The User Id is : ",user_id);
if(!event.data.val()){
return console.log('A Notification has been deleted from database : ', notification_id);
}
const fromUser = admin.database().ref(/notification/${user_id}/{notification_id}
).once(value);
return fromUser.then(fromUserResult => {
const from_user_id = fromUserResult.val().from;
console.log('You have new notification from : ', from_user_id);
const userQuery = admin.database().ref(`/Users/${user_id}/${notification_id}`).once('value');
return userQuery.then(userResult => {
const userName = userResult.val();
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 : `${userName} has sent you request`,
icon : "default"
}
};
return admin.messaging().sendToDevice(token_id , payload).then(response => {
console.log('This was the Notifiaction Feature');
return null;
});
});
});
}); }); `
sollution for----
error Each then() should return a value or throw promise/always-return
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 logging output above.
try by editing index.js
use this code--
return admin.messaging().sendToDevice(token_id, payload).then(response => {
console.log('This was the notification Feature');
return null;
}).catch(error => {
console.error(error);
res.error(500);
});
instead of ---
return admin.messaging().sendToDevice(token_id, payload).then(response => {
console.log('This was the notification Feature');
});
Show less
In my log, I am getting this error! Please help me. It's very important! Thank you!
In my log, I am getting this error! Please help me. It's very important! Thank you!
Have you found any solution for this issue??
exports.helloWorld = functions.database.ref('notification/{id}').onWrite(evt => { const payload = { notification:{ title : 'Message from Cloud', body : 'This is your body', badge : '1', sound : 'default' } };
return admin.database().ref('fcm-token').once('value').then(allToken => {
if(allToken.val()){
console.log('token available');
const token = Object.keys(allToken.val());
return admin.messaging().sendToDevice(token,payload);
}else{
return console.log('No token available');
}
});
}
----this worked for me instead of: console.log('No token available'); use: return console.log('No token available');
this is because then() should return something
exports.helloWorld = functions.database.ref('notification/{id}').onWrite(evt => { const payload = { notification:{ title : 'Message from Cloud', body : 'This is your body', badge : '1', sound : 'default' } };
return admin.database().ref('fcm-token').once('value').then(allToken => { if(allToken.val()){ console.log('token available'); const token = Object.keys(allToken.val()); return admin.messaging().sendToDevice(token,payload); }else{ return console.log('No token available'); } });
}
----this worked for me instead of: console.log('No token available'); use: return console.log('No token available');
this is because then() should return something
this one too worked for me thank you Atominac !!!
exports.helloWorld = functions.database.ref('notification/{id}').onWrite(evt => { const payload = { notification:{ title : 'Message from Cloud', body : 'This is your body', badge : '1', sound : 'default' } };
return admin.database().ref('fcm-token').once('value').then(allToken => { if(allToken.val()){ console.log('token available'); const token = Object.keys(allToken.val()); return admin.messaging().sendToDevice(token,payload); }else{ return console.log('No token available'); } });
}
----this worked for me instead of: console.log('No token available'); use: return console.log('No token available');
this is because then() should return something
Worked for me too. Thank you man!
In my log, I am getting this error! Please help me. It's very important! Thank you!
Have you solve this issue.
In my log, I am getting this error! Please help me. It's very important! Thank you!
Hi @Developer-AP Are you able to solve?? I have same issue
In my log, I am getting this error! Please help me. It's very important! Thank you!
Hi @Developer-AP Are you able to solve?? I have same issue
Can you please share the complete error and the code snippet giving this error.
In my log, I am getting this error! Please help me. It's very important! Thank you!
Hi, please check in your code, you'll find somewhere you are using an object without define it. Your compile is seeing some thing like this undefined.user_id .
Or you can share your code for more details
hello, teacher ! i have an issue when i am trying to deploy a function witch is in index.js file, a take all your code witch your publish to github for notification, but i have this issue:warning nesting promise promise/no-nesting error Each the() should return a value or throw promise/always-return. Please help me, I'm using FirebaseCloud messaging 11.0.4 and nodev8.4 for windows. i'm dont understand why my code dont work