簡體   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