javascript—当我尝试在firebase中部署我的函数时,它会显示“错误:函数未正确部署”如何解决这个问题?

flvlnr44  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(227)

我想通过firebase云功能通过firebase云发送消息。下面是我的代码

  1. const functions = require("firebase-functions");
  2. const admin = require('firebase-admin');
  3. admin.initializeApp(functions.config().firebase);
  4. const axios = require('axios');
  5. //import axios from 'axios';
  6. exports.abc = functions.pubsub.schedule('every 50 minutes').onRun(async (context) => {
  7. let response=await axios.get(
  8. 'https://coronavirus-19-api.herokuapp.com/countries/bangladesh'
  9. );
  10. console.log(response.data);
  11. let body=response.data.todayDeaths;
  12. console.log(body);
  13. let message = {
  14. notification: {
  15. 'title': 'Today death',
  16. 'body': `${body}`,
  17. },
  18. topic:'allUser'
  19. };
  20. admin.messaging().send(message)
  21. .then(response=>{
  22. console.log("Successfully sent",response);
  23. }).catch(error=>{
  24. console.log("failed",response);
  25. });
  26. console.log('This will be run every 2 minutes!');
  27. return null;
  28. });

但是当我试图部署我的函数时,我得到了一个错误

  1. Functions deploy had errors with the following functions:
  2. abc(us-central1)
  3. To try redeploying those functions, run:
  4. firebase deploy --only "functions:abc"
  5. To continue deploying other features (such as database), run:
  6. firebase deploy --except functions
  7. Error: Functions did not deploy properly.

这是firebase云函数日志中的错误通知

  1. Provided module can't be loaded.
  2. Did you list all required modules in the package.json dependencies?
  3. Detailed stack trace: Error: Cannot find module 'axios'
  4. Require stack:

而且

  1. Error: function terminated. Recommended action: inspect logs for termination reason.
  2. Additional troubleshooting documentation can be found at
  3. https://cloud.google.com/functions/docs/troubleshooting#logging Function cannot be
  4. initialized.
  5. {"code":3,"message":"Function failed on loading user code. This is likely due to a bug in the
  6. user code. Error message: Error: please examine your function logs to see the error cause:
  7. https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional
  8. troubleshooting documentation can be found at
  9. https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit
  10. https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting
  11. documentation."},"authenticationInfo":

如何解决这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题