我在将通知功能部署到firebase时遇到了困难。
我也使用了npm run clean但错误显示在其中 -
npm ERR! missing script: clean
index.js代码如下 -
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.pushNotification =
functions.database.ref('/Notifications/{user_id}/{notification_id}').onWrite(event => {
const user_id = event.params.user_id;
const notification = event.params.notification;
console.log('We have a notification to send to : ', user_id);
if(event.data.val()){
return console.log('A Notification has been deleted feom the database :', notification_id);
}
const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken).once('value');
return deviceToken.then(result => {
const token_id = result.val();
const payload = {
notification: {
title : "Friend Request",
bosy : "You have received a new Friend Request",
icon : "default"
}
};
return admin.messaging().sendToDevice(/*Token ID*/, payload).then(response => {
console.log('This was the notification Feature');
});
});
});
命令提示符中的firebase部署错误是 -
C:\Users\NIHIR\Desktop\MilApp\notificationFunction>firebase deploy
=== Deploying to 'milapp2-55dfb'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint
C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions
> eslint .
C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions\index.js
19:61 error Parsing error: Unterminated template
✖ 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 logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\NIHIR\AppData\Roaming\npm-cache\_logs\2018-03-10T22_49_06_402Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
如何解决此错误?
在Windows 10中使用它。 提前谢谢。
即使纠正了错误,我在部署firebase时再次收到错误 -
C:\Users\NIHIR\Desktop\MilApp\notificationFunction\functions\index.js
33:53 error Parsing error: Unexpected token ,
✖ 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 logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\NIHIR\AppData\Roaming\npm-cache\_logs\2018-03-11T11_27_17_307Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
答案 0 :(得分:1)
错误信息是:
19:61 error Parsing error: Unterminated template
它指的是此行上的模板字符串未终止的事实:
const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken).once('value');
您错过了该参考字符串的结束反引号。它应该是这样的:
const deviceToken = admin.database().ref(`/Users/${user_id}/deviceToken`).once('value');