![](/img/trans.png)
[英]Could not find com.google.firebase:firebase-messaging:16.0.8
[英]firebase function Puppeteer Could not find Chromium GCP
我在谷歌雲上使用 GCP 已經很長時間了,我想運行一個使用 Puppeteer 的雲函數,但不幸的是,我收到以下錯誤。
未處理的錯誤錯誤:找不到 Chromium(修訂版 1069273)。 這可能發生,如果
npm install
)或我的代碼是
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
降級 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.