我想通过firebase云功能通过firebase云发送消息。下面是我的代码
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const axios = require('axios');
//import axios from 'axios';
exports.abc = functions.pubsub.schedule('every 50 minutes').onRun(async (context) => {
let response=await axios.get(
'https://coronavirus-19-api.herokuapp.com/countries/bangladesh'
);
console.log(response.data);
let body=response.data.todayDeaths;
console.log(body);
let message = {
notification: {
'title': 'Today death',
'body': `${body}`,
},
topic:'allUser'
};
admin.messaging().send(message)
.then(response=>{
console.log("Successfully sent",response);
}).catch(error=>{
console.log("failed",response);
});
console.log('This will be run every 2 minutes!');
return null;
});
但是当我试图部署我的函数时,我得到了一个错误
Functions deploy had errors with the following functions:
abc(us-central1)
To try redeploying those functions, run:
firebase deploy --only "functions:abc"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
这是firebase云函数日志中的错误通知
Provided module can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'axios'
Require stack:
而且
Error: function terminated. Recommended action: inspect logs for termination reason.
Additional troubleshooting documentation can be found at
https://cloud.google.com/functions/docs/troubleshooting#logging Function cannot be
initialized.
{"code":3,"message":"Function failed on loading user code. This is likely due to a bug in the
user code. Error message: Error: please examine your function logs to see the error cause:
https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional
troubleshooting documentation can be found at
https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit
https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting
documentation."},"authenticationInfo":
如何解决这个问题?
暂无答案!
目前还没有任何答案,快来回答吧!