c3js / c3

:bar_chart: A D3-based reusable chart library
http://c3js.org
MIT License
9.35k stars 1.39k forks source link

TypeError: c3.generate is not a function #2747

Closed lasseeee closed 4 years ago

lasseeee commented 4 years ago

I just upgraded from

C3 version: 0.7.11 D3 version: 5.15.0

to

C3 version: 0.7.12 D3 version: 5.15.0

And all charts that were working are now broken with the error:

TypeError: c3.generate is not a function

I'm loading the charts like this at the end of the file:

    $(function() {
        var chart = c3.generate({

        });
    });
kt3k commented 4 years ago

How do you load c3.js? Do you use webpack?

lasseeee commented 4 years ago

Yes. It's loaded using Webpack (Laravel Mix) with window.c3 = require('c3');

jakubsobel commented 4 years ago

I have the same issue after the latest release. I'm using webpack 4.41.5 and latest changes in c3 exports broke the dynamic imports for me. The workaround is to use c3.default.generate or revert to older version of the c3.

In 0.7.11 this works fine:

import('c3')
  .then(c3 => c3.generate({...}))

In 0.7.12 I need to use:

import('c3')
  .then(c3 => c3.default.generate({...}))
kt3k commented 4 years ago

https://github.com/c3js/c3/pull/2740 seems to have affected webpack build. Webpack uses module field instead of main if module is present in package.json.