Firebase 云函数:无法读取typescript程式码中axios套件使用之undefined的属性'post'

wi3ka0sx  于 2022-11-23  发布在  iOS
关注(0)|答案(1)|浏览(89)

我尝试在google cloud函数中托管以下逻辑。当我使用模拟器执行此函数时,我总是得到⚠ functions: TypeError: Cannot read property 'post' of undefined
我尝试以不同的方式导入Axios包,但没有成功。这是与我的代码有关还是我缺少了一些firebase配置?

import axios from "axios";

export const sendSlackMessage = functions.https.onRequest(async (request, response) => {
  const slackUrl = functions.config().slackconfig.webhookurl;
  await axios.post(slackUrl, request.body)
    .then((value) => {
      console.log(value.data);
      response.sendStatus(200);
    })
    .catch((reason) => {
      response.send(`Failed, ${reason}`);
    });
});
tp5buhyn

tp5buhyn1#

确保已在函数目录中安装了axios

cd functions/
 npm i axios

相关问题