Hello,
I’m currently attempting to include some browserified node modules (crypto and others) into my k6 script. While i’ve gotten it to “work” I have found there is a performance penalty per VU. I have tried to limit the use of my import and came upon one idea was to conditionally import inside of the setup function (presumably this may run the import only once instead of in each VU’s JS environment which doesn’t need the import).
Something like this (contrived example):
// global setup, called once
export function setup () {
let done = false;
if (createData) {
const crypto = import('./utils/crypto.dist.js').then((mod) => {
done = true;
return mod;
});
while (!done) {
setTimeout(() => { console.log("loading..."); }, 1000);
}
// do something with crypto
}
}
However it appears the dynamic import() function is not supported in k6? I get unexpected token on the ^import line from babel. Any ideas would be appreciated how I could either dynamically import (if it’s possible) or perhaps another way to reduce the per VU overhead of importing large modules. xk6/crypto doesn’t support my use case unfortunately. Thanks!