question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] "Cannot read property 'launch' of undefined"

See original GitHub issue

Hi Team,

I am playing with AWS Lambda and Playwright.

with “playwright-aws-lambda”: “^0.5.2”, “playwright-core”: “^1.0.1”, works fine

but with “playwright-aws-lambda”: “^0.5.2”, “playwright-core”: “^1.2.1”, does not work.

what could be a problem?

my Code:

const playwright = require('playwright-aws-lambda');

exports.handler = async (event, context) => {
  let result = null;
  let browser = null;

  try {
    const browser = await playwright.launchChromium();
    const context = await browser.newContext();

    const page = await context.newPage();
    await page.goto(event.url || 'https://google.com');

    console.log('Page title: ', await page.title());
  } catch (error) {
    throw error;
  } finally {
    if (browser !== null) {
      await browser.close();
    }
  }
};

Error Message:

{
  "errorType": "TypeError",
  "errorMessage": "Cannot read property 'launch' of undefined",
  "trace": [
    "TypeError: Cannot read property 'launch' of undefined",
    "    at Object.launchChromium (/opt/node_modules/playwright-aws-lambda/dist/src/chromium.js:90:47)",
    "    at async Runtime.exports.handler (/var/task/api/poc1/handler.js:8:21)"
  ]
}

tnx a lot

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aslushnikovcommented, Aug 21, 2020
0reactions
osmeniacommented, Jul 23, 2020

Hi Max,

I created new layer with:

package.json

....
  "license": "ISC",
  "dependencies": {
    "playwright-aws-lambda": "^0.5.2",
    "playwright-chromium": "^1.2.1",
    "playwright-core": "npm:playwright-chromium@1.2.1"
  }
} 

Error:

{
  "errorType": "TypeError",
  "errorMessage": "Cannot read property 'launch' of undefined",
  "trace": [
    "TypeError: Cannot read property 'launch' of undefined",
    "    at Object.launchChromium (/opt/nodejs/node_modules/playwright-aws-lambda/dist/src/chromium.js:90:47)",
    "    at processTicksAndRejections (internal/process/task_queues.js:97:5)",
    "    at async Runtime.exports.handler (/var/task/index.js:8:21)"
  ]
}

an then i deleted “playwright-chromium”: “^1.2.1” from json file and uploaded new layer, with

  "dependencies": {
    "playwright-aws-lambda": "^0.5.2",
    "playwright-core": "npm:playwright-chromium@1.2.1"
  }

this does not help.

am i doing something wrong?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer launcher error results with undefined - Stack Overflow
Works import Puppeteer, { Browser, PDFOptions } from "puppeteer"; browser = await Puppeteer.launch({}); // Doesn't work import { launch, ...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
cannot read properties of undefined (reading 'locator') - You.com
There are 3 main reasons the "Cannot read properties of undefined" error occurs: Accessing a property on a variable that stores an undefined...
Read more >
puppeteer-chat/Lobby - Gitter
... TypeError: Cannot read property 'toString' of undefined. i tried . ... my code works when i do const browser = await puppeteer.launch({headless:...
Read more >
ERROR: Cannot read property 'split' of undefined (Docker ...
Hi, When i run the below code on my local N8N (npm installed) in function node , the code work fine and i...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found