-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Error: ENOENT: no such file or directory, open '/var/bin/chromium.br' #24
Comments
Well, found the problem after digging some more. What happens is that the layer places files inside the lambda at Now the code for the function static get executablePath(): Promise<string> {
if (existsSync('/tmp/chromium') === true) {
for (const file of readdirSync('/tmp')) {
if (file.startsWith('core.chromium') === true) {
unlinkSync(`/tmp/${file}`);
}
}
return Promise.resolve('/tmp/chromium');
}
const input = join(__dirname, '..', 'bin');
const promises = [
LambdaFS.inflate(`${input}/chromium.br`),
LambdaFS.inflate(`${input}/swiftshader.tar.br`),
];
if (/^AWS_Lambda_nodejs(?:10|12|14|16|18)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) {
promises.push(LambdaFS.inflate(`${input}/aws.tar.br`));
}
return Promise.all(promises).then((result) => result.shift());
} The problem is this: const input = join(__dirname, '..', 'bin');
Quick Fix proposal: refactor static get executablePath(): Promise<string> {
if (existsSync('/tmp/chromium') === true) {
for (const file of readdirSync('/tmp')) {
if (file.startsWith('core.chromium') === true) {
unlinkSync(`/tmp/${file}`);
}
}
return Promise.resolve('/tmp/chromium');
}
let input = '';
__dirname === '/var/task' ? input = '/opt/nodejs/node_modules/@sparticuz/chromium/bin' : input = (0, path_1.join)(__dirname, "..", "bin");
const promises = [
LambdaFS.inflate(`${input}/chromium.br`),
LambdaFS.inflate(`${input}/swiftshader.tar.br`),
];
if (/^AWS_Lambda_nodejs(?:10|12|14|16|18)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) {
promises.push(LambdaFS.inflate(`${input}/aws.tar.br`));
}
return Promise.all(promises).then((result) => result.shift());
} |
Same issue here: Node.js version: 16.6.0 package.json: {
"dependencies": {
"puppeteer-core": "19.3.0",
},
"devDependencies": {
"@sparticuz/chromium": "108.0.3",
}
} And a lambda layer. Error message:
Lambda code: import chromium from '@sparticuz/chromium'
import puppeteer from 'puppeteer-core'
puppeteer.launch({
executablePath: await chromium.executablePath,
args: chromium.args,
defaultViewport: chromium.defaultViewport,
headless: chromium.headless,
ignoreHTTPSErrors: true,
}) |
Another one here |
With the new version v109.0.0 still failing |
Is there any way to work around this? Getting this error in a Netlify function and totally blocked right now. |
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. |
@jdahdah I only can copy the code provided by @MarceloEmmerich to replace the function |
I get |
#18 will fix this, help wanted |
Happy to help on #18, however I think there is a difference in the use case. #18 reads as we should be able to explicitly pass the location of the brotli files, in other words, a scenario where we know exactly where these reside. This should not be the standard case IMHO. The standard case should remain as it is today, it just needs to check one more "default" location to automatically work with more deployment mechanisms. Having known alternative locations is of course a cool feature to have for the reasons mentioned in #18 . |
Agree, I'm not sure the performance implications of having multiple locations to check though. Testing would need to be done to insure the already pretty slow chromium doesn't get even slower because of that. |
Question, how does this work with containerised Typescript lambdas? https://docs.aws.amazon.com/lambda/latest/dg/typescript-image.html. I am noticing that I only get this error when I use the example in to aws doc. When I look inside the docker container I This is the aws doc reference example - has anyone gotten this to work with chromium? |
can you post your |
Thanks for the response. I am using both puppeteer-core and puppeteer (just testing the differences at the moment - will use pupeeteer-core)
Might it have something to do with the Dockerfile that those docs prescribe - The resulting container seems to have only the minified js files. |
Not very familiar with Docker deployments, but I would guess that it only bundles the |
I am also having exactly the same problem. Making it unusable in the lambda. Does anybody know if it works if you go to a earlier version? |
if you get the above error and you are using the layer approach, try replacing function executablePath(): Promise<string> {
const input = '/opt/nodejs/node_modules/@sparticuz/chromium/bin';
const promises = [
LambdaFS.inflate(`${input}/chromium.br`),
LambdaFS.inflate(`${input}/swiftshader.tar.br`),
LambdaFS.inflate(`${input}/aws.tar.br`),
];
return Promise.all(promises).then((result) => result.shift());
} and then whan you launch puppeteer you use this function and not the default one: const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
}); The actual |
This solution works well for me, thank you |
I've published v109.0.1 which supports an input variable in exectuablePath(). To fix the OP, you can use |
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 a similar problem with the folder |
Thank you @carlosdp - that was very helpful for me. I also wanted to follow-up and share that if you're using |
Do you have an example project that shows how you rigged this up? |
Not a public one, no. It's pretty simple though, just adding that line to the netlify.toml should make it work |
Thanks! Was trying to update 11ty/api-screenshot to get it working for me on Netlify. Need to dig a little deeper into the screenshotting function I think. |
If using next.js: #147 think it can be configured with webpack regardless |
Environment
chromium
Version: 108puppeteer-core
Version: 19.3.0nodejs14.x
andnodejs16.x
-->Expected Behavior
adding the layer and launching the browser works
Current Behavior
Steps to Reproduce
puppeteer-core
as prod dep@sparticuz/chromium
as dev dep-->
Possible Solution
The text was updated successfully, but these errors were encountered: