I’m having trouble with my Firebase cloud function that uses puppeteer-extra. When the function runs, it says Puppeteer is missing and tells me to install it. But I’ve already got it installed in my package.json. I even tried installing it again, but no luck.
Here’s what my package.json looks like:
{
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1",
"puppeteer": "^5.4.1",
"puppeteer-extra": "^3.1.15",
"puppeteer-extra-plugin-stealth": "^2.6.3"
}
}
And here’s how I’m setting up Puppeteer in my function:
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());
exports.myFunction = functions.https.onCall((data, context) => {
// Function code here
});
The error message says Puppeteer is missing and suggests installing it. I tried switching to regular Puppeteer, but then I got a deployment error. Any ideas what’s going on?
I’ve dealt with this exact problem before, and it can be super frustrating. One thing that worked for me was making sure I was using the correct runtime for my Cloud Functions. Firebase recently switched to Node.js 16 as the default, which can cause issues with older Puppeteer versions.
Try updating your package.json to use Puppeteer 13.5.0 or later, which is compatible with Node.js 16. Also, in your firebase.json file, explicitly set the runtime to nodejs16:
{
"functions": {
"runtime": "nodejs16"
}
}
If that doesn’t solve it, you might need to bundle Puppeteer with your function code. I’ve had success using the @sparticuz/chromium
package along with puppeteer-core
. This approach ensures you have a compatible Chrome binary available in your function environment.
Don’t forget to run npm install
and redeploy your functions after making these changes. It’s a bit of a hassle, but once you get it working, it’s smooth sailing from there!
I encountered a similar issue with Puppeteer in my Firebase cloud functions. The problem might be related to how Firebase handles dependencies. Try moving Puppeteer and its related packages to ‘devDependencies’ instead of ‘dependencies’ in your package.json. This ensures they’re installed during deployment but not included in the final package.
Also, make sure you’re using the latest version of the Firebase CLI and have deployed your functions recently. Sometimes, outdated deployments can cause unexpected behavior.
If that doesn’t work, you could try using the ‘puppeteer-core’ package instead and explicitly specifying the Chrome path in your code. This approach has worked for me in tricky deployment scenarios.
Lastly, double-check your function’s memory allocation. Puppeteer can be resource-intensive, so you might need to increase the allocated memory in your Firebase configuration.
hey man, i feel ur pain. had this issue b4. try checking ur function’s execution environment. sometimes the prob is firebase not installing deps correctly. u might need to manually include puppeteer in ur deployment package. also, make sure ur using compatible versions of puppeteer and node. good luck!