Webpack5 bundler xk6

I was trying to setup a bundler (webpack) in order to be able to use node libs during test execution. Although the bundler is created correctly (I test it outside the test script and it works) when I want to execute the script with k6 I get this error trace. Maybe there is some incompatibility or some configuration that I am missing?

ERRO[0000] There were problems with the specified script configuration: - executor default: function 'default' not found in exports

UPDATE: I have tried to use webpack 4 and it is working as expected. This lib has some vulnerabilities and I would like to update to webpack 5, but it seems that doing the same with the new version is not working (still getting same error). Any idea?
PS. The library that I am trying to bundle so far is json-schema-faker
(json-schema-faker - npm)

Hi @hernanmateikastuart, welcome to the community forum!

Unfortunately I don’t think there are many webpack (5 or otherwise) experts on the k6 team at this point.

The repo is old and kind of not really maintained, because it did two things for k6:

  1. it added the ability to import some node modules
  2. made mem (and sometimes CPU) usage on k6 lower as it used less functionality that k6 does not support but used to polyfill.
  3. technically also adds support for mroe JS features that are still not supported in k6.

The thing is that 2 is … almost not an issue and there is practically no memory or cpu improvements. It might make the startup times better, but even that requires scripts that are thousands of lines. And this will be no longer even at all true once Native ESM support · Issue #3265 · grafana/k6 · GitHub is implemented.

1 has always been mostly … not working due to:

  1. a lot of npm packages requiring nodejs native modules which webpack can’t polyfill (for examle process) - which for example makes any library doing IO (networkign or file one) completely not working
  2. a lot npm packages are … big. This is not so bad some times but they are usually meant to be loaded once or nubmer of cores on the machines times. K6 on the other hand is usually ran with hundereds if not thousands of VUs each of which need to load that 500kb library.

3 while still valid hasn’t really been that maintained if at all :(.

Having said all that - I did try to get webpack 5 working … and spend an hour + trying to make polyfill work - they didn’t. Or at least I am still left with one of the libraries requireing process … so can’t help you. You might have better luck with just asking in webpack support or maybe even just ignoring the “security problems” - pretty sure all of the ones I have seen have to do with cross site stuff which is completely irrelevant for k6.

My other general recommendation is to just import from unpkg as in

import jsf from "https://unpkg.com/json-schema-faker@0.5.3/dist/bundle.js"

(you can download this locally I guess and use that).

This usually works for some packages, and I don’t remember going through webpack helping more then just importhing this so :person_shrugging:

Hope this helps you and sorry for the slow reply

Thanks for your reply @mstoykov, I will try this and let know!
Many thanks for your ideas! :slight_smile: