Xk6 binary cannot use experimental features

I was trying to use an extension for protobuf support along with grpc extension that support streaming. When I launch the output binary using

./k6 run test.js

I get this error

[0000] GoError: unknown module: k6/experimental/grpc

I don’t get this error if I run the script using the system k6 binary but of course it fails to find the extension imports

Any idea how to solve this?
I’m using version 0.47

Hi @shoukryelfahl

Welcome to the community forum :wave:

Can you share a bit more context so we can help you figure this out?

  • What extensions are you using?
    • Can you share the command you use to build the k6 binary / the build steps?
  • Can you share a sanitized version of test.js?

With this, we can reproduce it locally and help figure out what could be going on.

Thanks!

1 Like

Thanks for the prompt response

I was using this extension to marshal protobuf to use with websockets and I used this command to build local k6 binary

xk6 build --with github.com/traveltime-dev/xk6-protobuf@latest --replace go.buf.build/grpc/go/prometheus/prometheus=buf.build/gen/go/prometheus/prometheus/protocolbuffers/go@latest --replace go.buf.build/grpc/go/gogo/protobuf=buf.build/gen/go/gogo/protobuf/protocolbuffers/go@latest

Note that I use --replace to avoid a reported bug. The advice was to use this parameter which worked

Please find the content of test.js and hello.proto
test.js

import { Client, Stream } from 'k6/experimental/grpc';
import { sleep } from 'k6';

const client = new Client();
client.load(['.'], 'hello.proto');

export default function (data) {

    client.connect('grpcbin.test.k6.io:9001', {
        plaintext: true
    });
    const stream = new Stream(client, 'hello/BidiHello', null);

    stream.on('data', function (data) {
        console.log(`Received message: ${data}`);
    });

    stream.on('end', function () {
        client.close();
    });

    stream.on('error', function (e) {
        console.log('Error: ' + JSON.stringify(e));
    });

    // send a message to the server
    const message = { greeting: 'Bert' };
    stream.write(message);
    client.close();
    sleep(1);
}

hello.proto

service HelloService {
  rpc SayHello(HelloRequest) returns (HelloResponse);
  rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse);
  rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse);
  rpc BidiHello(stream HelloRequest) returns (stream HelloResponse);
}

message HelloRequest {
  string greeting = 1;
}

message HelloResponse {
  string reply = 1;
}

when using the ./k6 run test.js it will throw the error but k6 run test.js will work without a problem

@shoukryelfahl

Your xk6 build command produces a v0.43.1 k6 binary at my computer. Maybe because it is referenced here: https://github.com/traveltime-dev/xk6-protobuf/blob/master/go.mod#L7

k6/experimental/grpc was not supported in v0.43.1

Try to run (set explicit k6 version for xk6):

K6_VERSION="v0.47.0" xk6 build --with github.com/traveltime-dev/xk6-protobuf@latest --replace go.buf.build/grpc/go/prometheus/prometheus=buf.build/gen/go/prometheus/prometheus/protocolbuffers/go@latest --replace go.buf.build/grpc/go/gogo/protobuf=buf.build/gen/go/gogo/protobuf/protocolbuffers/go@latest

3 Likes

@bandorko It worked. Thank you :pray:

1 Like