-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Brief summary
Since the removal of the K6_COMPATIBILITY_MODE=experimental_enhanced environment option, there is no way to run the k6 docker image with Typescript code:
docker run --rm -i grafana/k6 run - <MyTypescriptFile.ts
will always fail.
k6 version
1.0.0
OS
Linux
Docker version and image (if applicable)
k6/1.0.0
Steps to reproduce the problem
The documentation at https://grafana.com/docs/k6/latest/get-started/running-k6/ provides instructions on how to run k6 through docker, i.e.
docker run --rm -i grafana/k6 run - <script.js
Alas, this only works for Javascript and not Typescript, as
docker run --rm -i grafana/k6 run - <MyTypescriptFile.ts
will complain about any type annotation, as k6 has no awareness of the piped stdin is in fact Typescript.
This is very similar to #4199 - except that https://grafana.com/docs/k6/latest/using-k6/javascript-typescript-compatibility-mode/ officially documents that K6_COMPATIBILITY_MODE=experimental_enhanced has been removed. The effect of that, though, is that there is no way to turn on Typescript mode.
Hence: k6 cli missing switch to enable Typescript mode, at least for the official "how to run k6 through docker" documented approach.
Expected behaviour
A cli flag is present that turns on Typescript mode.
After adding that flag, say --typescript, the following command will work,
echo "function log(message: string) {} export default function() {}" | docker run --rm -i grafana/k6:1.0.0 run --typescript -
Actual behaviour
Run
echo "function log(message: string) {} export default function() {}" | docker run --rm -i grafana/k6:1.0.0 run -
and get
time="2025-05-08T06:01:16Z" level=error msg="GoError: file:///-: Line 1:21 Unexpected token :\n" hint="script exception"