chrome-aws-lambda: [BUG] Cannot find module 'puppeteer-core/lib/Browser'
Trying to execute README example, the following error occurred.
Environment
chrome-aws-lambda
Version: 3.1.1puppeteer
/puppeteer-core
Version: 5.1.0- OS: Linux
- Node.js Version: 12.x
- Lambda / GCF Runtime: nodejs12.x
Expected Behavior
Should have returned example.com content.
Current Behavior
Following error occurs:
Lambda execution failed with status 200 due to customer function error: Cannot find module 'puppeteer-core/lib/Browser'
Require stack:
- /var/task/node_modules/chrome-aws-lambda/source/puppeteer/lib/Browser.js
- /var/task/node_modules/chrome-aws-lambda/source/index.js
- /var/task/app.js
No Browser module expored in the following path: ‘puppeteer-core/lib/Browser’
Steps to Reproduce
Lambda functions: memory is 1024M, timeout is 3000ms.
const chromium = require('chrome-aws-lambda');
exports.handler = async (event, context, callback) => {
let result = null;
let browser = null;
try {
browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
let page = await browser.newPage();
await page.goto(event.url || 'https://example.com');
result = await page.title();
} catch (error) {
return callback(error);
} finally {
if (browser !== null) {
await browser.close();
}
}
return callback(null, result);
};
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 21
- Comments: 20
i had to move away from
chrome-aws-lambda
completely but did find a solution by following this: https://www.npmjs.com/package/@sparticuz/chromium.as the docs advise, i created a layer for a specific chromium version that shipped with the version of puppeteer-core i was using, added it to my function, and successfully ran a (very) simple script.
basic idea:
here’s the setup i got working:
using v16 was a leftover config from trying to mix and match older runtimes with various versions of
chrome-aws-lambda
andpuppeteer-core
. have yet to try with v18 but intend to do so and update this thread.13.7.0 works fine for me
Also downgrading to versions 3.0.4 of
chrome-aws-lambda
andpuppeteer-core
works for me@benjaminDanis does it work on Node v18?
As a workaround I am using the regular
puppeteer
at 5.2, the paths for that were already fixed in: https://github.com/alixaxel/chrome-aws-lambda/commit/f4d1fed53f0a20782900483b7c11539ba13faad9To keep my lambda size down I run
rm -r node_modules/puppeteer/.local-chromium
prior to uploading.This has as an additional benefit that pptr-testing-library/extend works as well.
Same error, and solved.
“puppeteer-core” seems to have changed the location of Browser.tsx from version 5. So I use version 4.0.1.
yarn remove puppeteer-core
and
yarn add puppeteer-core@4.0.1
I use this until I next update.
@JadeMin nodev18 does work, just confirmed.
I can confirm this works with nodev20 as well. That is the solution @benjaminDanis proposed