Node Js application modules cannot be accessed in k6 after webpack bundle

I have a node JS application where there exist multiple modules for header and URL of APIs. I want to reuse those modules in my k6 script.

  • I tried webpack bundling
  • Then accessing the bundle.js in the k6 script
  • Then, running the script as usual with “k6 run k6-script.js” but didnt work.

Any changes that I can make in this bundling or running process?

Accessing the bundle.js like this:
import hello from ‘…/…/config/dist/bundle’;

This is what the webpack.config.js looks like:

const path = require('path');
var webpack = require('webpack');
module.exports = {
    mode: 'production',
    entry: 'testing.client.helper.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
        libraryTarget: "commonjs2",
    module: {
        rules: [{ test: /\.js$/, use: 'babel-loader' }],
    target: 'web',
    externals: /^(k6|https?\:\/\/)(\/.*)?/,

Hi @Enthusiast,
welcome to the community forum.

What error are you getting from k6? If it doesn’t find the file then ensure that the specified path is correct.
Can you post a simplified and reproducible version of your script so I can give more detailed suggestions?

I hope it helps.