How to bundle scripted dashboards with webpack?

I want to bundle a grafana’s scripted dashboard with webpack to modularize it.

As a start, I am trying to bundle a simple test script provided by grafana as an example. The sample example is working, but when I bundle it with webpack with a very minimal configuration, the output script is not working. I am getting the following error :

Script dashboard error TypeError: Cannot read property ‘rows’ of undefined

const path = require(‘path’);

// webpack.config.js

module.exports = {
  entry: './src/scripted.js',
  output: {
    filename: 'scripted_NEW.js',
    path: path.resolve(__dirname, 'dist'),
  },
  mode: 'production'
};

What am I missing ?

Reproduction repo

1 Like