chromium: [BUG] Error: ENOENT: no such file or directory, open '/var/bin/chromium.br'

Environment

  • chromium Version: 108
  • puppeteer-core Version: 19.3.0
  • Node.js Version: 14.x and 16.x
  • Lambda nodejs14.x and nodejs16.x -->

Expected Behavior

adding the layer and launching the browser works

Current Behavior

2022-12-01T20:25:16.992Z	83285b39-c65f-4d14-99ab-cbecd1546d68	ERROR	[Error: ENOENT: no such file or directory, open '/var/bin/chromium.br'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/var/bin/chromium.br'
}

Steps to Reproduce

  • build the zip file lie described here: https://github.com/Sparticuz/chromium#aws-lambda-layer
  • double-checked the ZIP is good (it is, contains “nodejs/node_modules”
  • project has puppeteer-core as prod dep
  • project has @sparticuz/chromium as dev dep
  • deployment with CDK
  • lambda code:
exports.handler = async (event: any) =>  {

  console.log(event);

  try {
    const browser = await puppeteer.launch({
        args: chromium.args,
        defaultViewport: chromium.defaultViewport,
        executablePath: await chromium.executablePath,
        headless: chromium.headless,
        ignoreHTTPSErrors: true,
    });
    return browser;
  } catch (err) {
    console.error(err);
  }
  return ''
}

–>

Possible Solution

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 25 (3 by maintainers)

Commits related to this issue

Most upvoted comments

For anyone that comes here trying to use this with Netlify Functions, you have to include this dependency as an external, and then it works out of the box. Otherwise, their build system tries to be smart and inline everything:

# netlify.toml
[functions]
external_node_modules = ["@sparticuz/chromium"]

I had this issue at one point when packaging my lambda with webpack.

my solution: use webpack externals to mark “@sparticuz/chromium” as an external dependency. Without this webpack will still package this code meaning that the directory resolution was having issues.

Thank you @carlosdp - that was very helpful for me.

I also wanted to follow-up and share that if you’re using pnpm, you’ll want to include a environment variable on your site called PNPM_FLAGS that has a value of --shamefully-hoist. Netlify recommended it for NextJS in this article, and it seems to have solved my package issue as well.