I’m experiencing difficulties while trying to deploy a cloud function using Puppeteer on Google Cloud Platform (GCP). I’m receiving an error message indicating that Chromium cannot be located. The error detail suggests that it may be due to either failing to install dependencies beforehand (for instance, using npm install
) or having an incorrect cache path configured (current path being: /root/.cache/puppeteer). Below is my code snippet:
export const myFunction = functions
.runWith({
timeoutSeconds: 120,
memory: '512MB' || '2GB',
})
.https.onCall(async (payload, context) => {
const browserInstance = await puppeteer.launch({ args: ['--no-sandbox'] });
const newPage = await browserInstance.newPage();
await newPage.goto('https://www.example.com/');
browserInstance.close();
return { message: 'success', code: 200 };
});
My package.json
contains:
"engines": {
"node": "16"
},
And the tsconfig.json
settings are:
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "ES2020",
"esModuleInterop": true,
"rootDir": "src"
},
}
I’ve also placed a configuration file .puppeteerrc.cjs
in the lib
directory. I’ve attempted several approaches, such as reinstalling modules, reviewing related questions on StackOverflow, and tweaking the setup, but the issue persists. What steps should I take to resolve this?