K6: Cannot Transpile K6 Script with URL import to ES5

Created on 28 Jan 2021  路  2Comments  路  Source: loadimpact/k6


Hello, I am trying to transpile K6 script into ES5. Yet, it is not working. I try to transpile following code based on the project from template-es6 repository: https://github.com/k6io/template-es6

Environment

  • k6 version: k6 v0.28.0 (2020-09-21T12:06:29+0000/v0.28.0-0-gdee9c4ce, go1.14.9, windows/amd64)
  • OS and version: Windows 10
  • Docker version and image, if applicable:

Expected Behavior


Transpiled code should work with --compatibility-mode=base flag

Actual Behavior


When I run k6 run --compatibility-mode=base XXX.js, it gives me following error:

ERRO[0000] GoError: https://jslib.k6.io/url/1.0.0/index.js: Line 2:115 Unexpected token ) (and 186 more errors) at reflect.methodValueCall (native)

Steps to Reproduce the Problem

  1. Take sample transpile project from https://github.com/k6io/template-es6
  2. Following is the sample code


// Creator: WebInspector 537.36

import { sleep, check, group } from "k6";
import http from "k6/http";

import { URL } from "https://jslib.k6.io/url/1.0.0/index.js";
import jsonpath from "https://jslib.k6.io/jsonpath/1.0.2/index.js";


export const options = {
  "maxRedirects": 0,
  "throw": true,
  "setupTimeout": "60s",
  "teardownTimeout": "60s",
  "batch": 1,
  "insecureSkipTLSVerify": true
}



export default function main() {
  let address, response;

  const vars = {};

  group('hello', function () { })

  // Automatically added sleep
  sleep(1);
}

3.After transpile the code, run it with --compatibility-mode=base flag.

bug evaluation needed js-compat

Most helpful comment

This issue has been moved to https://github.com/k6io/template-es6/issues/1. Closing this one.

All 2 comments

Hi @3wweiweiwu,

It seems that webpack(which is what is used in combination with babel to make template-es6 work) does not have the ability to donwload remote imports(once that are imported by https url instead of by a file path). Using https://github.com/roneyrao/remote-webpack-plugin should work, but I haven't tried it and doesn't seem to be in development anymore so :man_shrugging: .

The easiest way to fix this will be to download the 2 scripts that you are importing remotely and import them locally :).

Hope this helps.

This issue has been moved to https://github.com/k6io/template-es6/issues/1. Closing this one.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

na-- picture na--  路  4Comments

Jonne picture Jonne  路  4Comments

athoune picture athoune  路  3Comments

kokokenada picture kokokenada  路  4Comments

StephenRadachy picture StephenRadachy  路  3Comments