Export global variable when using Browserify

I am using Browserify and would like to use D3.js along with the radar chart component.

import 'd3';
import 'radar-chart-d3';

The radar chart component returns an error Uncaught ReferenceError: d3 is not defined.

I tried using the option insertGlobalVarsfor the browser:

browserify: {
    bundleName: 'main.js',
    prodSourcemap: false,
    insertGlobalVars: {
      d3: function(file, dir) {
        return 'require("d3")';
      }
    }
  }

However, this does not change anything in the situation. I know that I can simply add require('d3')radar diagrams to the top of the .js file, but I would like to avoid this.

What other way to open a variable d3for a global scope so other files can use d3.

+4
source share
1 answer

Insert this into package.json:

"eslintConfig": {
  "globals": {
    "d3": true
  }
}
0

All Articles