最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Puppeteer error on Heroku: Could not find Chromium - Stack Overflow

programmeradmin0浏览0评论

I'm a little new to deploying/hosting Node apps and Puppeteer.

But, I'm facing an issue though with my app on Heroku when trying to use Puppeteer.

The full error is:


Error: Could not find Chromium (rev. 1056772). This can occur if either

2022-11-10T06:44:07.938983+00:00 app[web.1]:  1. you did not perform an installation before running the script (e.g. `npm install`) or

2022-11-10T06:44:07.938983+00:00 app[web.1]:  2. your cache path is incorrectly configured (which is: /app/.cache/puppeteer).

2022-11-10T06:44:07.938983+00:00 app[web.1]: For (2), check out our guide on configuring puppeteer at /guides/configuration.

2022-11-10T06:44:07.938984+00:00 app[web.1]:     at ChromeLauncher.resolveExecutablePath (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:120:27)

2022-11-10T06:44:07.938984+00:00 app[web.1]:     at ChromeLauncher.executablePath (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:166:25)

2022-11-10T06:44:07.938985+00:00 app[web.1]:     at PuppeteerNode.executablePath (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/PuppeteerNode.js:162:105)

2022-11-10T06:44:07.938985+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:29:145)

2022-11-10T06:44:07.938985+00:00 app[web.1]:     at Module._compile (node:internal/modules/cjs/loader:1159:14)

2022-11-10T06:44:07.938986+00:00 app[web.1]:     at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)

2022-11-10T06:44:07.938986+00:00 app[web.1]:     at Module.load (node:internal/modules/cjs/loader:1037:32)

2022-11-10T06:44:07.938986+00:00 app[web.1]:     at Module._load (node:internal/modules/cjs/loader:878:12)

2022-11-10T06:44:07.938986+00:00 app[web.1]:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

2022-11-10T06:44:07.938987+00:00 app[web.1]:     at node:internal/main/run_main_module:23:47

My code for index.js is:


const puppeteer = require('puppeteer-extra')

const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha')

const StealthPlugin = require('puppeteer-extra-plugin-stealth')

const { executablePath } = require('puppeteer')

const axios = require('axios')

//pupeteer plugins

puppeteer.use(

    RecaptchaPlugin({

        provider: {

            id: '2captcha',

            token: 'XXX'

        },

        visualFeedback: true //colorize reCAPTCHAs (violet = detected, green = solved)

    })

)

puppeteer.use(StealthPlugin())

//pupeteer crawl

try {

    puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], headless: true, executablePath: executablePath(), ignoreHTTPSErrors: true }).then(async browser => {

        console.log('Running tests..')

        const page = await browser.newPage()

        await page.goto('')

        await page.setViewport({ width: 1680, height: 857 })

        await page.waitForTimeout(5000)

        await page.screenshot({ path: 'testresult.png', fullPage: true })

        await browser.close()

        console.log(`All done, check the screenshot. ✨`)

    })

} catch (error) {

    console.error(error);

}

And these are my build packs in Heroku:

I've been battling with these for a few days and tried everything :(

Thank you!!

I've tried adding the necessary flags:

args: ['--no-sandbox', '--disable-setuid-sandbox']

And also the build pack:

These are the common solutions people have mentioned on other issue threads.

I'm a little new to deploying/hosting Node apps and Puppeteer.

But, I'm facing an issue though with my app on Heroku when trying to use Puppeteer.

The full error is:


Error: Could not find Chromium (rev. 1056772). This can occur if either

2022-11-10T06:44:07.938983+00:00 app[web.1]:  1. you did not perform an installation before running the script (e.g. `npm install`) or

2022-11-10T06:44:07.938983+00:00 app[web.1]:  2. your cache path is incorrectly configured (which is: /app/.cache/puppeteer).

2022-11-10T06:44:07.938983+00:00 app[web.1]: For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.

2022-11-10T06:44:07.938984+00:00 app[web.1]:     at ChromeLauncher.resolveExecutablePath (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:120:27)

2022-11-10T06:44:07.938984+00:00 app[web.1]:     at ChromeLauncher.executablePath (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:166:25)

2022-11-10T06:44:07.938985+00:00 app[web.1]:     at PuppeteerNode.executablePath (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/PuppeteerNode.js:162:105)

2022-11-10T06:44:07.938985+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:29:145)

2022-11-10T06:44:07.938985+00:00 app[web.1]:     at Module._compile (node:internal/modules/cjs/loader:1159:14)

2022-11-10T06:44:07.938986+00:00 app[web.1]:     at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)

2022-11-10T06:44:07.938986+00:00 app[web.1]:     at Module.load (node:internal/modules/cjs/loader:1037:32)

2022-11-10T06:44:07.938986+00:00 app[web.1]:     at Module._load (node:internal/modules/cjs/loader:878:12)

2022-11-10T06:44:07.938986+00:00 app[web.1]:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

2022-11-10T06:44:07.938987+00:00 app[web.1]:     at node:internal/main/run_main_module:23:47

My code for index.js is:


const puppeteer = require('puppeteer-extra')

const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha')

const StealthPlugin = require('puppeteer-extra-plugin-stealth')

const { executablePath } = require('puppeteer')

const axios = require('axios')

//pupeteer plugins

puppeteer.use(

    RecaptchaPlugin({

        provider: {

            id: '2captcha',

            token: 'XXX'

        },

        visualFeedback: true //colorize reCAPTCHAs (violet = detected, green = solved)

    })

)

puppeteer.use(StealthPlugin())

//pupeteer crawl

try {

    puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], headless: true, executablePath: executablePath(), ignoreHTTPSErrors: true }).then(async browser => {

        console.log('Running tests..')

        const page = await browser.newPage()

        await page.goto('https://bot.sannysoft.com')

        await page.setViewport({ width: 1680, height: 857 })

        await page.waitForTimeout(5000)

        await page.screenshot({ path: 'testresult.png', fullPage: true })

        await browser.close()

        console.log(`All done, check the screenshot. ✨`)

    })

} catch (error) {

    console.error(error);

}

And these are my build packs in Heroku:

I've been battling with these for a few days and tried everything :(

Thank you!!

I've tried adding the necessary flags:

args: ['--no-sandbox', '--disable-setuid-sandbox']

And also the build pack: https://github.com/jontewks/puppeteer-heroku-buildpack

These are the common solutions people have mentioned on other issue threads.

Share Improve this question asked Nov 10, 2022 at 7:01 RainManRainMan 1111 gold badge1 silver badge3 bronze badges 3
  • If I was you I would be deploying a docker container with chromium's path as executablePath in puppeteer. Using a custom driver is far better than the one that the puppeteer installs. – Partho KR Commented Nov 10, 2022 at 15:09
  • Same issue here – conor909 Commented Nov 10, 2022 at 19:49
  • 1 @ParthoKR could you elaborate on how this would be done please? Sounds like an interesting option. – RainMan Commented Nov 11, 2022 at 11:55
Add a comment  | 

5 Answers 5

Reset to default 10

I actually just came across this problem today. To break down why this is happening: Puppeteers new v19 updates how .cache is stored. This causes issues with builds and deployment. As such if your build can't find .cache then it can't find the chromium and it crashes.

Your two options are to tell your program to run a v18 version of puppeteer or simply put this config in the same directory as your index.js

project-directory/.puppeteerrc.cjs:

const {join} = require('path');

/**
 * @type {import("puppeteer").Configuration}
 */
module.exports = {
  // Changes the cache location for Puppeteer.
  cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};

Make sure to call it .puppeteerrc.cjs and afterwards, uninstall then reinstall puppeteer and add .cache to your .gitignore

If this still doesn't work you can try other config options at:
https://pptr.dev/guides/configuration/

I ran into this problem the other day. I built/packaged an Electron app with Puppeteer on Windows Server 2022 (a Vultr instance) and then tried running the built executable on a Windows 11 Home laptop. I tried the officially suggested solution of using the .puppeteerrc.cjs file. It did not work.

The only solution that worked for me was downgrading to Puppeteer 18.1.0. Hope that helps someone.

Puppeteer from v19 and later changed how the install of chromium is cached. In order to get it to work correctly with heroku, you need to add the following to your scripts object in your package.json:

"scripts": {
  ...
  "heroku-postbuild": "mkdir ./.cache && mv /app/.cache/puppeteer ./.cache"
},

Without the above, heroku will not include the new cache directory that puppeteer uses, and your app will fail saying it cannot find chromium.

Source: https://github.com/jontewks/puppeteer-heroku-buildpack

I fixed that issue by adding another buildpack https://github.com/heroku/heroku-buildpack-google-chrome and two environment variables to setup puppeteer:

PUPPETEER_EXECUTABLE_PATH = /app/.apt/usr/bin/google-chrome
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = true

not facing this issue with puppeteer: 17.1.3

发布评论

评论列表(0)

  1. 暂无评论