Comments (18)
@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.
chrome-aws-lambda/source/index.js
Lines 134 to 137 in 661e61d
chrome-aws-lambda/source/index.js
Lines 172 to 174 in 661e61d
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:
return await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath || process.env.CHROME_PATH,
headless: chromium.headless || process.env.HEADLESS_MODE,
});
It looks like only the elements that override puppeteer are included in the chrome-aws-lambda
package.
chrome-aws-lambda/source/index.js
Lines 179 to 194 in 661e61d
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 the node_modules
inside to your NODE_PATH
, like so:
export NODE_PATH=${PWD}/nodejs/node_modules
If you don't want to use the included layer, you can just install puppeteer as well:
npm i puppeteer-core --save-dev
from chrome-aws-lambda.
I was able to mitigate this by doing a npm i puppeteer-core --save
. Also, I changed the example code to not just context.succeed()
(this will yield a 503 error when using API Gateway), but to context.succeed({ body: JSON.stringify(result), statusCode: 200 });
from chrome-aws-lambda.
@zeeshanaligold Just published a new wiki page regarding your issue and suggested workaround.
https://github.com/alixaxel/chrome-aws-lambda/wiki/HOWTO:-Local-Development
from chrome-aws-lambda.
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 add puppeteer-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.
from chrome-aws-lambda.
It's always something simple, isn't it? I was including puppeteer-core as an excluded package in serverless. D'oh!
package:
exclude:
- node_modules/puppeteer-core/**
Thanks for your quick response and help on this issue!
from chrome-aws-lambda.
this didn't throw an error like:
"errorMessage":"Chromium revision is not downloaded. Run \"npm install\" or \"yarn install\"","errorType":"Error","stackTrace":["Launcher.launch (/var/task/node_modules/puppeteer-core/lib/Launcher.js:119:15)","<anonymous>"]}
from chrome-aws-lambda.
No, itβs the exact Message as seen above. I think puppeteer-core needs to be defined as dependency for this package.
from chrome-aws-lambda.
@jdcauley Having this error. I think chrome.executablePath is returning null.
from chrome-aws-lambda.
Same error happening
{
"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)"
]
}
from chrome-aws-lambda.
As I get a little bit lost with the answers I will summarize for further help. After having the problem with Cannot find module 'puppeteer-core/lib/FrameManager'
the simple thing we can do is to:
npm i puppeteer-core --save
Then, you get the error of Error: Chromium revision is not downloaded
so you "Set the CHROME_PATH env variable to your Chrome local installation". Perhaps:
CHROME_PATH=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome npm run local
from chrome-aws-lambda.
I'd like to confirm based on @WesPainter's comment, if we are using AWS for production, it sounds like we should do npm i puppeteer-core -D
, so that locally we install the puppeteer core while on production we can use the Amazon layers. Is that correct?
If we're using Google Cloud Functions, would we need to download the puppeteer-core for production as well? I don't know of an equivalent to layers in GCP.
from chrome-aws-lambda.
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 });
And to be extremely clear, you have to require in puppeteer-core into your lambda code.
// Goes to dependencies
$npm i puppeteer-core --save
// require both puppeteerCore and chrome-aws-lambda in your sourcecode
const puppeteerCore = require('puppeteer-core');
const chromium = require('chrome-aws-lambda');
from chrome-aws-lambda.
You don't have to require it explicitly as the module requires it for us (see the snippet I posted above). See the README for a lambda ready example that doesn't require puppeteer explicitly.
from chrome-aws-lambda.
I'm getting the same issue. I have included puppeteer-core in package.json and at the top of my file, and I can confirm that FrameManager exists inside node_modules/puppeteer-core/lib/FrameManager.js
It works fine locally, but fails once deployed. Below is the full error. Any suggestions are much appreciated!
START RequestId: 22929fef-fcab-4e6c-8f93-46ee78a6842c Version: $LATEST
2020-01-08T15:58:14.374Z 22929fef-fcab-4e6c-8f93-46ee78a6842c INFO generating email report2020-01-08T15:58:14.376Z 22929fef-fcab-4e6c-8f93-46ee78a6842c INFO { key1: 'value1', key2: 'value2', key3: 'value3' }2020-01-08T15:58:14.378Z 22929fef-fcab-4e6c-8f93-46ee78a6842c INFO Error: Cannot find module 'puppeteer-core/lib/FrameManager'
Require stack:
- /var/task/node_modules/chrome-aws-lambda/source/puppeteer/lib/FrameManager.js
- /var/task/node_modules/chrome-aws-lambda/source/index.js
- /var/task/dist/endicia/index.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/var/task/node_modules/chrome-aws-lambda/source/puppeteer/lib/FrameManager.js:6:11)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/var/task/node_modules/chrome-aws-lambda/source/puppeteer/lib/FrameManager.js',
'/var/task/node_modules/chrome-aws-lambda/source/index.js',
'/var/task/dist/endicia/index.js',
'/var/runtime/UserFunction.js',
'/var/runtime/index.js'
]
}2020-01-08T15:58:14.379Z 22929fef-fcab-4e6c-8f93-46ee78a6842c ERROR Invoke Error {"errorType":"Error","errorMessage":"false","stack":["Error: false"," at _homogeneousError (/var/runtime/CallbackContext.js:13:12)"," at postError (/var/runtime/CallbackContext.js:30:54)"," at done (/var/runtime/CallbackContext.js:57:7)"," at fail (/var/runtime/CallbackContext.js:69:7)"," at /var/runtime/CallbackContext.js:105:16"]}END RequestId: 22929fef-fcab-4e6c-8f93-46ee78a6842c
REPORT RequestId: 22929fef-fcab-4e6c-8f93-46ee78a6842c Duration: 7.71 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 78 MB Init Duration: 161.43 ms
from chrome-aws-lambda.
When I inspect the zip that gets uploaded (in .serverless), for some reason, the puppeteer-core folder is not there, which is why it is failing. But I'm not sure why that's happening since all other dependencies are there as far as I can tell.
from chrome-aws-lambda.
@simsketch Seems serverless related - probably the pack step is ignoring some libs somehow.
I don't use serverless myself but there're are so many issues around it that I should try it out...
Could you share a minimal serverless repro setup so that I can look into it on my end?
from chrome-aws-lambda.
I think, as stated before, puppeteer-core needs to be added as (peer) dependency to this project.
from chrome-aws-lambda.
@tobilg Can't do that as puppeteer
itself is also a valid peer dependency to it (when this project started puppeteer-core
hadn't even been released yet). This is an issue with serverless bundling and should be addressed as such IMO.
from chrome-aws-lambda.
Related Issues (20)
- [BUG] Error: Cannot find module 'node_modules\puppeteer-core\lib\cjs\puppeteer\common\Browser' HOT 5
- is this project is active and new versions expected ? HOT 7
- [BUG] Screenshots are only getting inline styles, no css HOT 1
- [BUG] Is this project dead? No node16 support? HOT 1
- [BUG] Failed to launch the browser process!\n\n\nTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md\n", HOT 26
- Warning: Max serverless function size of 50 MB compressed or 250 MB uncompressed reached
- [REQUEST] Implement puppeteer-extra-plugin-stealth HOT 3
- [BUG] Images are not rendering in img tag or background-img HOT 6
- [REQUEST] Load chromium.font after launching Chromium
- [BUG] Why is puppeteer-core needed?
- [BUG] Cannot find module ...node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser' HOT 2
- Can't run Puppeteer in AWS Lambda. HOT 10
- [BUG] Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (901912).
- How can we implement x-ray?
- [REQUEST] ARM support on lambda HOT 2
- [BUG] Does Not Work With Node 16 or 18 HOT 10
- [BUG] runtime.unhandledpromiserejection
- [BUG] - Scrolling doesn't work in AWS Lambda HOT 1
- Module parse failed: Unexpected token (1:10) HOT 4
- Feature Request: Update Puppeteer & Chromium Packages to Latest Versions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chrome-aws-lambda.