Skip to content

[Bug]: latest react-chart-js2 5.2.0 doesn't work with storybook #1166

Not planned

Description

@psnb88

Would you like to work on a fix?

  • Check this if you would like to implement a PR, we are more than happy to help you go through the process.

Current and expected behavior

Usage:- I use storybook( 6.5.13, webpack 4.6.4) ,react (react-scripts :5.0.1), react-chart-js2(5.2.0) ,chart.js(4.2.1) in my project.

Current behaviour :- npm run storybook throws exception " ERROR in ./node_modules/chart.js/dist/chart.js 568:17
Module parse failed: Unexpected token (568:17)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

| };
| class DatasetController {

static defaults = {};
| static datasetElementType = null;
| static dataElementType = null;

Expected : storybooking react chart.js components should work.

Reproduction

NA

chart.js version

4.2.1

react-chartjs-2 version

5.2.0

Possible solution

Workaround tried:-

  • downgrading chartjs to 2.9.4 seems to work.
  • excluding files and folder which had reference to react-chart-js2 didn't work. code used for excluding filesand folder is below

webpackFinal: async (config, {configType}) => {
config.module.rules.push({
test: /.js$/,
exclude: [
path.resolve(__dirname, '../path/'),
,
],
});
return config;
},

Activity

  1. lkarvec commented on May 18, 2023

    @lkarvec

    Works on my machine, Running 5.2.0 / 4.3.0

  2. SabrinaFZ commented on Jun 19, 2023

    @SabrinaFZ

    I'm having the same issue, any progress on this?

  3. enamodeka commented on Jun 23, 2023

    @enamodeka

    Same config as OP, same error here

  4. rjousse18 commented on Aug 24, 2023

    @rjousse18

    same here

  5. dangreen commented on Nov 30, 2026

    @dangreen
    Collaborator

    Closing: this is about how Chart.js itself behaves or is configured, while react-chartjs-2 passes data, options and plugins to Chart.js as they are. The Chart.js docs cover it: https://www.chartjs.org/docs/latest/ If it turns out to be a bug, please report it to Chart.js: https://github.com/chartjs/Chart.js/issues

    Storybook 6 with webpack 4 cannot parse the class fields of the Chart.js 4 build; webpack 5 or a newer Storybook handles it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions