Javascript 尝试部署函数时出错
我正在尝试部署我的代码,但遇到错误 我的索引代码是:Javascript 尝试部署函数时出错,javascript,firebase,firebase-realtime-database,google-cloud-functions,Javascript,Firebase,Firebase Realtime Database,Google Cloud Functions,我正在尝试部署我的代码,但遇到错误 我的索引代码是: 'use strict' const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendNotification = functions.database.ref('/Notifications/
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification =
functions.database.ref('/Notifications/{receiver_user_id}/{notification_id}')
.onWrite((data, context) =>
{
const receiver_user_id = context.params.receiver_user_id;
const notification_id = context.params.notification_id;
console.log('We have a notification to send to :' , receiver_user_id);
if (!data.after.val())
{
console.log('A notification has been deleted :' , notification_id);
return null;
}
const DeviceToken = admin.database().ref(`/Users/${receiver_user_id}/device_token`).once('value');
return DeviceToken.then(result =>
{
const token_id = result.val();
const payload =
{
notification:
{
title: "New Chat Request",
body: `you have a new Chat Request, Please Check.`,
icon: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload)
.then(response =>
{
console.log('This was a notification feature.');
});
});
});
显示的错误如下:
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\Admin\AppData\Roaming\npm-cache\_logs\2020-06-02T11_48_47_185Z-debug.log
events.js:287
throw er; // Unhandled 'error' event
^
}
Error: functions predeploy error: Command terminated with non-zero exit code1
The error shown in C:\Users\Admin\AppData\Roaming\npm-cache_logs\2020-06-02T11_48_47_185Z-debug.log :
error code ELIFECYCLE
error errno 1
error functions@ lint: `eslint .`
error Exit status 1
error Failed at the functions@ lint script.
error This is probably not a problem with npm. There is likely additional logging output above.
verbose exit [ 1, true ]
您需要在此处捕获错误:
然后(响应=>
{
log('这是一个通知功能');
}).catch(错误=>此处处理错误)
您的Android应用程序如何与javascript代码交互?是否按照错误提示检查了C:\Users\Admin\AppData\Roaming\npm-cache\u logs\2020-06-02T11\u 48\u 47\u 185Z-debug.log
?里面有什么?这是一个皮棉问题,对吧,检查你的皮棉脚本。如果您的代码位于类似src
的文件夹中,请将脚本更改为eslint src/*.js
。即使它在根目录中,.eslint忽略节点_模块并使其成为eslint*.js
请告诉我如何更改它。我不明白您是否正确安装了eslint软件包?或者可能是您错误地删除了它。请重新检查,否则请按@Mr Robot在回答中提到的那样放置.catch来处理您的错误。