[英]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
这可能发生,如果
npm install
) ornpm install
)或 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.