daniel
daniel

Reputation: 35733

Firebase Cloud Functions deploy async function with NPM 8

my functions package.json

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

my old non async functions get deployed. But not my new async one:

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);
};

when running: firebase deploy --only functions:screenshot I get the error:

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

what can I do?

Upvotes: 0

Views: 453

Answers (1)

daniel
daniel

Reputation: 35733

exports.screenshot = functions.https.onRequest(async (req, res) => {
...
});

did it for me

Upvotes: 1

Related Questions