[BUG] Cannot find module 'puppeteer-core/lib/Browser'
Altantur opened this issue ยท 20 comments
Trying to execute README example, the following error occurred.
Environment
chrome-aws-lambdaVersion: 3.1.1puppeteer/puppeteer-coreVersion: 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);
};Same error Here!!
Also downgrading to versions 3.0.4 of chrome-aws-lambda and puppeteer-core works for me
Same error !
I'm getting the same error:
dependencies:
"dependencies": { "chrome-aws-lambda": "^3.1.1", "puppeteer-core": "^5.2.0" }
service: chrome-node
provider:
name: aws
runtime: nodejs12.x
functions:
hello:
handler: index.handler
memorySize: 1600MB
timeout: 30
events:
- http:
path: /
method: get
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://google.com');
result = await page.title();
} catch (error) {
return callback(error);
} finally {
if (browser !== null) {
await browser.close();
}
}
return callback(null, result);
};
Downgrade puppeteer-core from 5.2 to 5.1 (npm install puppeteer@5.1)
And then, to fix this issue, you need to change these three files,
source/puppeteer/lib/Browser.js, Page.js, FrameManager.js
Change the 6 line:
From
puppeteer-core/lib/Browser
To
Super = require('puppeteer-core/lib/cjs/common/Browser').BrowserContext;
This will fix this issue, and I'm looking forward to updating :)
@heathera2016 It worked now, thank you. Seems like 'puppeteer-core' changed its path.
Please create PR for the next update.
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.
That did not fix it for me. Still getting the same error. did you downgrade chrome-aws-lambda too?
@cthorner try this - #122 (comment) worked for me
@cthorner try this - #122 (comment) worked for me
Did you just npm install @types/puppeteer-core?
@kaykhancheckpoint but make sure you have 5.1.0 installed - I was having some issues with anything above that
As a workaround I am using the regular puppeteer at 5.2, the paths for that were already fixed in: f4d1fed
To 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.
Is there a solution for this? Nothing worked for me. I tried removing "serverless" from next.config.js
13.7.0 works fine for me
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:
- reference the chromium support page for proper version mapping
- create archive of the proper chromium version for a layer, publish zip to s3, create new version
- add layer to function
- use chromium args with puppeteer-core
here's the setup i got working:
// lambda fn
runtime: Node.js 16.x
architecture: x86_64
memory: 512MB
// index.js
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium");
exports.handler = async (event) => {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto("https://example.com");
const title = await page.title();
const content = await page.content();
await browser.close();
return {
title,
content,
}
}// invocation results
Duration: 8712.36 ms Billed Duration: 8713 ms Memory Size: 512 MB Max Memory Used: 489 MB Init Duration: 371.51 ms
using v16 was a leftover config from trying to mix and match older runtimes with various versions of chrome-aws-lambda and puppeteer-core. have yet to try with v18 but intend to do so and update this thread.
@benjaminDanis does it work on Node v18?
@benjaminDanis kinda late but v18 works?
@JadeMin nodev18 does work, just confirmed.
I can confirm this works with nodev20 as well. That is the solution @benjaminDanis proposed
I am also getting this error