Xk6 run works, yet xk6 build doesn't

Hello! Hope your weekend is going great:)
So in my tests I was forced to use a dataset (basically a huge folder of different images), due to the fact of having cache on DB side. Whenever I sent an attachment it got cached, so I needed a lot of different images/documents in each request.
Since k6 can’t list files from directories, I’ve managed to create a quite small module, which basically lists files from directory I provide in parameters and returns those as a slice of strings, their names.
I tried to test my module with xk6 run and it went great, everything worked just fine.
But when I tried to do xk6 build (and xk6 build --with both targeting local files and my github) it just didn’t work out. A lot of errors, they were different, probably due to my inexperience with go.mod
Here is the repo: https://github.com/Nesodus/xk6-listfiles
Could you please teach me “how to Go” in this case, because I’ve spent a whole day trying to find a solution, but didn’t get a success in my attempts:(

Also I would be glad to share this module with others of course, with PR’s open for modifications and different functionality. First tho, I have to successfully build it:)

Hi @Nesodus,

If you look at the error message you will notice this part:

go: github.com/Nesodus/xk6-listfiles@v0.0.0-20220414143656-d19ec9ad64a6: parsing go.mod:
        module declares its path as: github.com/Nesodus/xk6-listfile
                but was required as: github.com/Nesodus/xk6-listfiles

Which tells yuo what the problems is - you have named your module without s in the go.mod file but your repo (and the way you import it) with s. So you can just add an s to the module name in go.mod and that will fix it.

I would also recommend that you start using the new API for the extension as what you are currently using might be deprecated and not work in a future k6 version.

On another note … I am not certain that what you are doing will help you due to deficiencies with working with uploading files. So depending on your use case listing the files in a directory isn’t your biggest problem :(.

You can at least test this through fixing the extension (as mentioned above) and see how it works before refactoring it with to the new API. I would also recommend just listing the file manually or using ls such as in

for (let i of __ENV.LS_OUT.split("\n")) {
export default () => { }
LS_OUT=`ls` k6 run script.js

I guess somethign similar can be made to run on windows with dir (? don’t remember if that is the command)

Hope this helps you

Hello and thank you for your extended answer.
Will definitely try methods you provided above keeping in mind that issue

@mstoykov Thank you, it took me a bit of time to understand how go.mod works, yet it worked and my extension did build successfully.
I have another question though, if what am I doing might be deprecated (and I’m not doing anything extraordinary, structure of module is taken from other modules), does that mean that other modules, like GitHub - avitalique/xk6-file: k6 extension for writing files can get deprecated as well?

can get deprecated as well?

The k6 team is deprecating the API - if the module maintainer(s) don’t update to the new API it will just not build with newer version of k6.

Whether, the maintainer of a particular extension will continue supporting it is completely different question.

As you can also see we have in the past made PRs to fix breaking changes in extensions. And we are likely to do it in the future as well. Just maybe not once we have hundreds of extensions.

1 Like