chrome-aws-lambda: Cannot find module 'puppeteer-core/lib/FrameManager'
I receive the following error when trying to run the usage example on AWS Lambda:
{
"errorMessage": "Cannot find module 'puppeteer-core/lib/FrameManager'",
"errorType": "Error",
"stackTrace": [
"Function.Module._resolveFilename (module.js:547:15)",
"Function.Module._load (module.js:474:25)",
"Module.require (module.js:596:17)",
"require (internal/module.js:11:18)",
"Object.<anonymous> (/var/task/node_modules/chrome-aws-lambda/source/puppeteer/lib/FrameManager.js:6:11)",
"Module._compile (module.js:652:30)",
"Object.Module._extensions..js (module.js:663:10)",
"Module.load (module.js:565:32)",
"tryModuleLoad (module.js:505:12)",
"Function.Module._load (module.js:497:3)"
]
}
I verified that the node_modules/chrome-aws-lambda/source/puppeteer/lib/FrameManager.js
file exists
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 18 (4 by maintainers)
@jdcauley, or for anyone who sees this:
If you are developing locally, the module checks for certain flags to determine whether to point to the included chrome build or return null.
https://github.com/alixaxel/chrome-aws-lambda/blob/661e61d8f1e2877cc69718789f2a2340d0608337/source/index.js#L134-L137
https://github.com/alixaxel/chrome-aws-lambda/blob/661e61d8f1e2877cc69718789f2a2340d0608337/source/index.js#L172-L174
You can either set these flags so that the path returns (wouldn’t recommend unless you’re on Amazon Linux), or otherwise instruct the launch command to find a local chrome if chromium returns null. Assuming you set a
CHROME_PATH
environment variable:@smxdevst
It looks like only the elements that override puppeteer are included in the
chrome-aws-lambda
package.https://github.com/alixaxel/chrome-aws-lambda/blob/661e61d8f1e2877cc69718789f2a2340d0608337/source/index.js#L179-L194
If you look in the ‘/chrome-aws-lambda/source/puppeteer’, you’ll only see those two files. The Layer includes the full
puppeteer-core
, so on Lambda all you need to do is add the zipped layer. On local, you can download the layer, unzip it, and add thenode_modules
inside to yourNODE_PATH
, like so:If you don’t want to use the included layer, you can just install puppeteer as well:
@zeeshanaligold Just published a new wiki page regarding your issue and suggested workaround.
https://github.com/alixaxel/chrome-aws-lambda/wiki/HOWTO:-Local-Development
I was able to mitigate this by doing a
npm i puppeteer-core --save
. Also, I changed the example code to not justcontext.succeed()
(this will yield a 503 error when using API Gateway), but tocontext.succeed({ body: JSON.stringify(result), statusCode: 200 });
It’s always something simple, isn’t it? I was including puppeteer-core as an excluded package in serverless. D’oh!
Thanks for your quick response and help on this issue!
Apologies everyone, this is a documentation shortcoming, I thought it was obvious but clearly it’s not.
There are two issues being discussed here:
Cannot find module 'puppeteer-core/lib/FrameManager'
error, andchrome.executablePath
beingnull
For the first, I will make a note in the README to stress out that
puppeteer[-core]
is required. I will also addpuppeteer-core
as a peer dependency now that it became the standard for serverless deployments.As for the second, I will create a Wiki page to better explain it, since it’s a recurring question.