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)

Most upvoted comments

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

  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.

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

@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 just context.succeed() (this will yield a 503 error when using API Gateway), but to context.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!

package:
  exclude:
    - node_modules/puppeteer-core/**

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:

  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.