Import path not found error in docker with xk6

HI folks. I"m having a rough time figuring out why I’m getting a path error when I use xk6. The following command throws the error below. I am using relative paths because using a full path means I’m locked into the path in a non-shareable manner. Also I don’t see a way to set the import module path using a dynamic parameter. that’s not the problem however. the problem I have is that running k6 or xk6 from the CLI works fine with script imports containing relative paths. when I use docker for xk6 it can’t find the path. when I use native k6 in a docker call it too executed as expected with a script using relative paths to import modules. :man_shrugging:t6:

I’ve tried mounting locally this way

--volume `pwd`:perf
--volume //`pwd`:/perf
--volume //`pwd`//://perf
docker run --disable-content-trust=true --volume //`pwd`//://perf -i xk6 run /perf/test_suites/get_scenario.js -o output-prometheus-remote --quiet -e K6_PROMETHEUS_FLUSH_PERIOD=10s -e K6_PROMETHEUS_REMOTE_URL=https://prom-domain/api/v1/push

time=“2022-10-26T18:17:27Z” level=error msg=“The moduleSpecifier "…/…/…/k6-utils-imported/1.1.0/index.js" couldn’t be found on local disk. Make sure that you’ve specified the right path to the file. If you’re running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they’re accessible by k6 from inside of the container, see Modules go.k6.io/k6/js.(*InitContext).Require-fm (native)\n\tat file:///perf/v1/GET/get_details.js:1:0(26)\n\tat go.k6.io/k6/js.(*InitContext).Require-fm (native)\n\tat file:///perf/test_suites/get_scenario.js:1:0(19)\n\tat native\n” hint=“script exception”

this use of k6 works fine with the same script(s)

docker run  --disable-content-trust=true --volume `pwd`/:/perf/ -i grafana/k6 run /perf/${params.SCRIPT4} --quiet

thoughts, suggestions, jokes?

I"ll be crawling into a hole the remainder of today. I was off by 1 directory “…” in the script path definition to the util.js :triumph:

too many dots… ignore this post.

2 Likes