GoError: unknown module: k6/execution

Hi there,

Whenever I try to import:

import { randomItem } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';

It throws the error:

./k6 -v run --vus 1 --duration 2s mytest.bundle.js
DEBU[0000] Logger format: TEXT
DEBU[0000] k6 version: v0.32.0 ((devel), go1.19.2, darwin/arm64)

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

DEBU[0000] Initializing the runner...
DEBU[0000] Loading...                                    moduleSpecifier="file:///...mytest.bundle.js" originalModuleSpecifier=mytest.bundle.js
DEBU[0000] Babel: Transformed                            t=472.828709ms
DEBU[0000] Loading...                                    moduleSpecifier="https://jslib.k6.io/expect/0.0.4/index.js" originalModuleSpecifier="https://jslib.k6.io/expect/0.0.4/index.js"
DEBU[0000] Fetching source...                            url="https://jslib.k6.io/expect/0.0.4/index.js?_k6=1"
DEBU[0000] Fetched!                                      len=7247 t=199.622416ms url="https://jslib.k6.io/expect/0.0.4/index.js?_k6=1"
DEBU[0001] Babel: Transformed                            t=552.074208ms
DEBU[0001] Loading...                                    moduleSpecifier="https://jslib.k6.io/ajv/6.12.5/index.js" originalModuleSpecifier="https://jslib.k6.io/ajv/6.12.5/index.js"
DEBU[0001] Fetching source...                            url="https://jslib.k6.io/ajv/6.12.5/index.js?_k6=1"
DEBU[0001] Fetched!                                      len=121974 t=81.160916ms url="https://jslib.k6.io/ajv/6.12.5/index.js?_k6=1"
DEBU[0001] Loading...                                    moduleSpecifier="https://jslib.k6.io/k6-utils/1.4.0/index.js" originalModuleSpecifier="https://jslib.k6.io/k6-utils/1.4.0/index.js"
DEBU[0001] Fetching source...                            url="https://jslib.k6.io/k6-utils/1.4.0/index.js?_k6=1"
DEBU[0001] Fetched!                                      len=4974 t=72.975792ms url="https://jslib.k6.io/k6-utils/1.4.0/index.js?_k6=1"
DEBU[0001] Babel: Transformed                            t=298.388916ms
ERRO[0001] GoError: unknown module: k6/execution
	at reflect.methodValueCall (native)
	at https://jslib.k6.io/k6-utils/1.4.0/index.js:2:1221(77)
	at https://jslib.k6.io/k6-utils/1.4.0/index.js:2:6148(3)
	at reflect.methodValueCall (native)
	at file:///.....mytest.bundle.js:497:53(172)
	at file:///....mytest.bundle.js:525:5(35)
	at file:///....mytest.bundle.js:530:13(2)  hint="script exception"
error: Recipe `test` failed on line 16 with exit code 107

It would be really great if I can get a fix for this!

P.S.: I have removed the full directory path with ....mytest.bundle.js

Edit: I have tried to uninstall and reinstall go and k6 but the still same issue is occurring.

Your k6 version is too old, the k6/execution API was added in k6 v0.34.0 and the current k6 version is v0.40.0 (with v0.41.0 slated to be released next week).

However, I see that it was compiled with the most recent Go version, so I assume you used xk6 to build a custom k6 build with some extension? If so, then the extension likely depends on this old v0.32.0 version of k6, so that’s what xk6 used. You can try to force xk6 to use the latest k6 version by running this:

xk6 build v0.40.0 --with github.com/your/extension

or even

xk6 build master --with github.com/your/extension

But there might have been some breaking changes in the k6 Go APIs in the meantime and the extension might not be able to be compiled that way. Which extension are you using, if that is indeed the case?

Thanks for the solution, it is working finally. I was trying to build:

xk6 build v0.40.0 --with github.com/dgzlopes/xk6-redis@latest

We should probably deprecate GitHub - dgzlopes/xk6-redis: A k6 extension for Redis., since we recently bundled the more recent (and official) GitHub - grafana/xk6-redis: A k6 extension to test the performance of a Redis instance. extension as k6/experimental/redis in all public k6 releases. That is, you don’t need to build a custom release with xk6 to use it, you can just import k6/experimental/redis from any official k6 build and it will work. Take a look here for more details and documentation: