Syntax Error: Unexpected token while bundling with webpack


My question is related to configuration of babel/webpack to be able to use nodeJS modules - and unrelated to K6 as such. Thanks in advance for any advise.

Here is my webpack configuration:

 var path = require('path');
 var webpack = require('webpack');
 module.exports = {
 mode: "production",
 entry: './sam-svt.js',
 output: {
     path: path.resolve(__dirname, '.'),
     libraryTarget: "commonjs",
     filename: 'app.bundle.js'
 module: {
     rules: [
             test: /\.js$/,
             exclude: /node_modules/,
             loader: 'babel-loader',
             options: {
                 plugins: ["node_modules/jsdoc-babel"]
 stats: {
     colors: true
 target: "node",
     externals: /k6(\/.*)?/,
 devtool: 'source-map'

Here is my package.json file:

  "name": "test-repo",
  "version": "1.0.0",
  "description": "test-repo",
  "main": "main.js",
  "devDependencies": {
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"babel-loader": "^8.0.6",
"core-js": "^3.0.1",
"moment": "^2.24.0",
"webpack": "^4.31.0",
"webpack-cli": "^3.3.2"
  "scripts": {
"webpack": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
  "keywords": [
  "author": "AAA",
  "dependencies": {
"custom-library": "^3.1.13"

The log is a bit confusing to me, but I have tried to include elements of note below:
msg="SyntaxError: file:///sam/app.bundle.js: Unexpected token (420:29407)\n 418 | * Copyright(c) 2014-2016 Douglas Christopher Wilson\n 419 | * MIT Licensed\n> 420 | *..../e.exports=function(e,t){if(!e)throw new TypeError(\"req argument is required\")at <eval>:2:28542(114)"

Note: The error happens when K6 is run, and not during the build process.

I have tinkered around using some information from external sources and some trial-and-error on my own, and at the outset it seems like my configuration does not like certain syntax that are used for comments (i.e. “/*! */”).
I say this because when I try and remove offending characters at the line specified in the error and re-bundle, the next error in the logs seems to move on from where it was (to the next place with similar syntax).

For example, running built code seems to fail at:

//! moment-timezone.js
//! version : 0.5.33
//! Copyright (c) JS Foundation and other contributors
//! license : MIT

Changing the code in the node_module to

// moment-timezone.js
// version : 0.5.33
// Copyright (c) JS Foundation and other contributors
// license : MIT

Moves the error during runtime to:


  • FileStreamRotator
  • Copyright(c) 2012-2017 Holiday Extras.
  • Copyright(c) 2017 Roger C.
  • MIT Licensed

Could someone offer some insight or share their experience with a similar issue ?

Thank you very much.

Hi there.

I wasn’t able to reproduce this with the files you provided and ran into other issues. Would you mind sharing a Git repo with a working project and the commands you used?

That said, the FileStreamRotator library probably wouldn’t work in k6, even if it’s transpiled and bundled by Webpack. Note that not all Node.js libraries work in k6, and anything related to the file system or streams likely wouldn’t work.

I’m not sure what’s failing at transpiling those comments though. Maybe someone with more experience with Babel/Webpack could jump in. Have you tried using the template-es6 repo as base?