You can run test scripts with different ECMAScript compatibility modes with the run --compatibility-mode CLI option or K6_COMPATIBILITY_MODE environment variable.
Currently two modes are available:
Your mileage may vary while running --compatibility-mode=base and also importing external dependencies. For instance, xml2js and cheerio currently do not work, while lodash does.
Note that require() is a custom k6 implementation of module loading, which doesn't behave in the same way as the require() call in Node.js. Specifically, it only handles loading of built-in k6 modules, scripts on the local filesystem, and remote scripts over HTTP(S), but it does not support the Node.js module resolution algorithm.
In case of syntax/parsing errors, the script will be transformed using Babel with specific plugins bringing the compatibility to ES2015(ES6)+. This means that features such as classes and arrow functions can be used. This does take some time to transpile and the produced code has slightly different line/column numbers.
Before v0.31.0, k6 included core.js v2 and even more Babel plugins in extended mode. This added around 2MB extra memory usage per VU and some of the transformations (generators, async/await) of Babel were still insufficient to get k6 working with these features.
There's a substantial difference in performance between both modes, as shown by GNU time below, especially when running tests with a large number of VUs: