繁体   English   中英

firebase 函数 Puppeteer 找不到 Chromium GCP

[英]firebase function Puppeteer Could not find Chromium GCP

我在谷歌云上使用 GCP 已经很长时间了,我想运行一个使用 Puppeteer 的云函数,但不幸的是,我收到以下错误。


未处理的错误错误:找不到 Chromium(修订版 1069273)。 这可能发生,如果

  1. 您在运行脚本之前没有安装(例如, npm install )或
  2. 您的缓存路径配置不正确(即:/root/.cache/puppeteer)。 对于 (2),请查看我们在https://pptr.dev/guides/configuration上配置 Puppeteer 的指南。 在 ChromeLauncher.resolveExecutablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:120:27) 在 ChromeLauncher.executablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/ node/ChromeLauncher.js:166:25) 在 ChromeLauncher.launch (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:70:37) 在 async /workspace/lib/index.js :122:21 在异步 /workspace/node_modules/firebase-functions/lib/common/providers/https.js:407:26

我的代码是


export const test = functions
  .runWith({
    timeoutSeconds: 120,
    memory: "512MB" || "2GB",
  })
  .https.onCall(async (data, context) => {
    const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
    const page = await browser.newPage();
    await page.goto("https://www.google.com/");

    browser.close();
    return { msg: "all good", status: 200 };
  });

我从这里复制了一个如何在 GCP 函数中使用 Puppeteer 的示例(在我的机器上运行),我还尝试了其他不使用 Puppeteer 的函数,这些函数工作正常(所以我确定问题出在 Puppeteer 上)。 我还尝试添加标志“--disable-setuid-sandbox”,但这没有用。 我正在用 Typescript 编写 firebase 函数。 我的 package.json 具有以下设置。

"engines": {
    "node": "16"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^10.2.0",
    "firebase-functions": "^3.21.0",
    "puppeteer": "^19.4.0"
  },
  "devDependencies": {
    "@types/puppeteer": "^7.0.4",
    "typescript": "^4.6.4"
  },
  "private": true

我的 tsconfig.json 文件具有以下设置。

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "ES2020",
    "esModuleInterop": true,
    "rootDir": "src",
  },
  "compileOnSave": true,
  "include": [
    "src",
    "node_modules/@types/puppeteer/index.d.ts"
  ]
}

根据此处,我在 lib 目录中也有 the.puppeteerrc.cjs 文件。

const {join} = require('path');

/**
 * @type {import("puppeteer").Configuration}
 */
module.exports = {
  // Changes the cache location for Puppeteer.
  cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};

我尝试将它添加到 index.js、index.ts、package.json、firebase.json 旁边,但这并没有改变它。 我尝试删除并重新安装 node_modules。 我试着关注 StackOverflow 的问题。 使用 Puppeteer 部署 firebase 功能说即使我启用了 --no-sandbox 也找不到 chrome

无法将 firebase 函数迁移到节点 10 运行时

puppeteer-in-firebase-functions-failed-to-launch-chrome

降级 puppeteer 有帮助:

npm remove puppeteer
npm install puppeteer@16.2.0 --save-dev

我遇到了类似的问题。 我能找到的最简单的修复方法是降级到 Puppeteer 16.2.0 版本。 它是 Puppeteer 的弃用版本,但它应该可以工作。

干杯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM