Git Product home page Git Product logo

Comments (18)

WesPainter avatar WesPainter commented on September 13, 2024 5

@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.

static get executablePath() {
if (this.headless !== true) {
return null;
}

static get headless() {
return ['AWS_LAMBDA_FUNCTION_NAME', 'FUNCTION_NAME', 'FUNCTION_TARGET'].some((key) => process.env[key] !== undefined);
}

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,
  });

@smxdevst

It looks like only the elements that override puppeteer are included in the chrome-aws-lambda package.

static get puppeteer() {
for (let overload of ['FrameManager', 'Page']) {
require(`${__dirname}/puppeteer/lib/${overload}`);
}
try {
return require('puppeteer');
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND') {
throw error;
}
return require('puppeteer-core');
}
}
}

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.

tobilg avatar tobilg commented on September 13, 2024 2

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.

alixaxel avatar alixaxel commented on September 13, 2024 2

@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.

alixaxel avatar alixaxel commented on September 13, 2024 1

Apologies everyone, this is a documentation shortcoming, I thought it was obvious but clearly it's not.

There are two issues being discussed here:

  1. Cannot find module 'puppeteer-core/lib/FrameManager' error, and
  2. chrome.executablePath being null

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.

simsketch avatar simsketch commented on September 13, 2024 1

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.

jdcauley avatar jdcauley commented on September 13, 2024

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.

tobilg avatar tobilg commented on September 13, 2024

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.

zeeshanaligold avatar zeeshanaligold commented on September 13, 2024

@jdcauley Having this error. I think chrome.executablePath is returning null.

Screenshot from 2019-06-03 09-45-14

from chrome-aws-lambda.

smxdevst avatar smxdevst commented on September 13, 2024

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)"
  ]
}

image

from chrome-aws-lambda.

duranmla avatar duranmla commented on September 13, 2024

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.

comolongo avatar comolongo commented on September 13, 2024

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.

SaniMusic avatar SaniMusic commented on September 13, 2024

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 });

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.

WesPainter avatar WesPainter commented on September 13, 2024

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.

simsketch avatar simsketch commented on September 13, 2024

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.

simsketch avatar simsketch commented on September 13, 2024

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.

alixaxel avatar alixaxel commented on September 13, 2024

@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.

tobilg avatar tobilg commented on September 13, 2024

I think, as stated before, puppeteer-core needs to be added as (peer) dependency to this project.

from chrome-aws-lambda.

alixaxel avatar alixaxel commented on September 13, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.