chromium: [BUG] Error: ENOENT: no such file or directory, open '/var/bin/chromium.br'
Environment
chromium
Version: 108puppeteer-core
Version: 19.3.0- Node.js Version: 14.x and 16.x
- Lambda
nodejs14.x
andnodejs16.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
- Adjusting dependencies Per https://github.com/Sparticuz/chromium/issues/24 — committed to aarongustafson/api-screenshot by aarongustafson 9 months ago
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:
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 calledPNPM_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.