简体   繁体   English

firebase 函数 Puppeteer 找不到 Chromium GCP

[英]firebase function Puppeteer Could not find Chromium GCP

I have been using GCP for a long time with google cloud, and I wanted to run a cloud function that uses Puppeteer, but unfortunately, I am getting the following error.我在谷歌云上使用 GCP 已经很长时间了,我想运行一个使用 Puppeteer 的云函数,但不幸的是,我收到以下错误。


Unhandled error Error: Could not find Chromium (rev. 1069273).未处理的错误错误:找不到 Chromium(修订版 1069273)。 This can occur if either这可能发生,如果

  1. you did not install before running the script (eg, npm install ) or您在运行脚本之前没有安装(例如, npm install )或
  2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer).您的缓存路径配置不正确(即:/root/.cache/puppeteer)。 For (2), check out our guide on configuring Puppeteer at https://pptr.dev/guides/configuration .对于 (2),请查看我们在https://pptr.dev/guides/configuration上配置 Puppeteer 的指南。 at ChromeLauncher.resolveExecutablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:120:27) at ChromeLauncher.executablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:166:25) at ChromeLauncher.launch (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:70:37) at async /workspace/lib/index.js:122:21 at async /workspace/node_modules/firebase-functions/lib/common/providers/https.js:407:26在 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

My code is我的代码是


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

I copy from here an example of how to use Puppeteer in the GCP function (worked on my machine), I also tried other functions that don't use Puppeteer, which work fine (so I am sure the problem is with Puppeteer).我从这里复制了一个如何在 GCP 函数中使用 Puppeteer 的示例(在我的机器上运行),我还尝试了其他不使用 Puppeteer 的函数,这些函数工作正常(所以我确定问题出在 Puppeteer 上)。 I also tried to add the flag "--disable-setuid-sandbox" but that didn't work.我还尝试添加标志“--disable-setuid-sandbox”,但这没有用。 I am writing the firebase function with Typescript.我正在用 Typescript 编写 firebase 函数。 My package.json has the following settings.我的 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

My tsconfig.json file has the following setting.我的 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"
  ]
}

I also have in the lib directory the.puppeteerrc.cjs file according to here .根据此处,我在 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'),
};

I tried adding it next to index.js, index.ts,package.json, firebase.json, but that did not change it.我尝试将它添加到 index.js、index.ts、package.json、firebase.json 旁边,但这并没有改变它。 I tried deleting and reinstalling node_modules.我尝试删除并重新安装 node_modules。 I tried to follow StackOverflow questions.我试着关注 StackOverflow 的问题。 Deploying firebase function with Puppeteer says chrome can't be found even thoough I have enabled --no-sandbox 使用 Puppeteer 部署 firebase 功能说即使我启用了 --no-sandbox 也找不到 chrome

Not able to migrate firebase functions to node 10 runtime 无法将 firebase 函数迁移到节点 10 运行时

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

downgrading puppeteer helped:降级 puppeteer 有帮助:

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

I faced a similar issue.我遇到了类似的问题。 The simplest fix that I could find was to downgrade to Puppeteer 16.2.0 version.我能找到的最简单的修复方法是降级到 Puppeteer 16.2.0 版本。 It is a deprecated version of Puppeteer but it should work.它是 Puppeteer 的弃用版本,但它应该可以工作。

Cheers干杯

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

相关问题 找不到 com.google.firebase:firebase-messaging:16.0.8 - Could not find com.google.firebase:firebase-messaging:16.0.8 如何在具有 firebase 身份验证的 GCP api 网关后面添加经过身份验证的云 function - How to add Authenticated cloud function behind GCP api gateway having firebase auth Android Studio 构建错误:Gradle - 找不到平台('com.google.firebase:firebase-bom:30.3.1') - Android Studio build error: Gradle - Could not find platform('com.google.firebase:firebase-bom:30.3.1') 使用 Firebase 在 CodeSandbox 上找不到/安装 babel 插件“proposal-decorators” - Could not find/install babel plugin 'proposal-decorators' on CodeSandbox with Firebase CocoaPods 找不到 pod“Firebase/CoreOnly”的兼容版本 - CocoaPods could not find compatible versions for pod "Firebase/CoreOnly" 如何在 GCP/Firebase 中创建 Central Auth 项目? - How To Create A Central Auth Project In GCP/Firebase? Gcp支持从firebase绑定服务账号? - Gcp support binding service account from firebase? 在使用 firebase 存储的 GCP 中运行 python 脚本 - Run python script in GCP that use firebase storage apache 光束与 gcp 云 function - apache beam with gcp cloud function GCP Https 功能 - 入口设置 - GCP Https Function - Ingress settings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM