Search code examples
javascripthighchartsecmascript-6webpackes6-module-loader

how to import highcharts with webpack and babel


I use ES6, Babel and webpack stack.

I have installed highcharts by npm (I prefer to use the official highcharts npm repo):

npm install highcharts-release --save

But, regular import (ES6) doesn't work as expected:

import highcharts from 'highcharts';

How can I import Highcharts via webpack import? Can you post a webpack.config.js example (or other way to config the plugins)?

Thanks.

EDIT

The error is:

Uncaught Error: Cannot find module "highcharts" webpackMissingModule @ review-chart.js:2(anonymous function) ....

Solution

  • 2022 Update Highcharts now have an official wrapper for React - https://github.com/highcharts/highcharts-react

    There is a NPM called commonjs-highcharts that solves it. Just run npm i commonjs-highcharts and import it:

    import highcharts from "commonjs-highcharts"
    

    Worked for me.