ERRO[0000] TypeError: Object has no member 'launch'

I am getting the below error while running a simple sample script.

ERRO[0000] TypeError: Object has no member 'launch'
        at file:///Users/afsalbacker/Desktop/k6/browser.js:4:34(8)
        at native  executor=per-vu-iterations scenario=default source=stacktrace

My code is:

import launcher from ‘k6/x/browser’;

export default function () {
  const browser = launcher.launch('chromium',{ headless: false });
  const context = browser.newContext();
  const page = context.newPage();
  page.goto('https://ecommerce.k6.io', { waitUntil: 'networkidle' })
}

My browser does not load because of this.


s

Hi @gm4afsal,

Welcome to the forums!

It looks like you are using a newer version of xk6-browser which contains a breaking change where the imports have changed.

Which version of xk6-browser are you running or what commands did you run to build a binary?

For the latest release of xk6-browser, this script should work:

import { chromium } from 'k6/x/browser';

export default function () {
  const browser = chromium.launch({ headless: false });
  const context = browser.newContext();
  const page = context.newPage();

  page.goto('https://test.k6.io', { waitUntil: 'networkidle' })
  .finally(() => {
    page.close();
    browser.close();
  });
}

Cheers,
Ankur

Hi @ankur

i see the below issue after the k6 upgrade to latest version:

ERRO[0000] Uncaught (in promise) TypeError: Cannot read property 'launch' of undefined or null

code I am using is:

const browser = chromium.launch({ headless: false });
  const context = browser.newContext();
  const page = context.newPage();

Hi @santosh,

Can you please give us the following details:

  1. The full script.
  2. The version of k6 you are working with.

A guess is that you are working with a newer version of k6 (v0.46.0+) where the API has changed. There is a migrations guide on how to migrate your test scripts to v0.46.0 of k6: Migrating to k6 v0.46

Cheers,
Ankur

1 Like