【问题标题】:Firebase Cloud Functions deploy async function with NPM 8Firebase Cloud Functions 使用 NPM 8 部署异步函数
【发布时间】:2018-08-13 23:24:07
【问题描述】:

我的函数 package.json

...
"dependencies": {
    "firebase-admin": "~5.13.0",
    "firebase-functions": "^2.0.0",
    "puppeteer": "^1.6.2"
},
"engines": {
    "node": "8"
}

我的旧非异步函数被部署。但不是我的新异步:

exports.screenshot = async  (req, res) => {
  const url = "https://google.de"; // req.query.url;

  if (!url) {
    return res.send('Please provide URL as GET parameter, for example: <a href="?url=https://example.com">?url=https://example.com</a>');
  }

  const browser = await puppeteer.launch({
    args: ["--no-sandbox"]
  });
  const page = await browser.newPage();
  await page.goto(url);
  const imageBuffer = await page.screenshot();
  await browser.close();

  res.set("Content-Type", "image/png");
  res.send(imageBuffer);
};

运行时:firebase deploy --only functions:screenshot 我得到了错误:

The following functions are found in your project but do not exist in your local source code:
        screenshot(us-central1)

我能做什么?

【问题讨论】:

  • 从 Node 7.6 开始支持异步/等待。你在检查脚本吗?
  • linting 没有错误。问题是部署脚本没有检测到它
  • 请编辑问题以更具体地显示错误是什么。是否有描述问题的命令行输出?
  • 我没有收到任何错误。未部署异步功能(已识别?)
  • 您是否在节点脚本的其他任何地方发出Module.exports?如果是这样,那将覆盖您的个人export

标签: firebase async-await google-cloud-functions


【解决方案1】:
exports.screenshot = functions.https.onRequest(async (req, res) => {
...
});

为我做的

【讨论】:

    猜你喜欢
    • 2023-04-10
    • 2022-07-28
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 2017-09-01
    • 2018-08-18
    • 2017-10-09
    相关资源
    最近更新 更多