Search code examples
javascriptchart.jssveltesveltekit

The requested module '/node_modules/.vite/deps/chart_js.js?v=425f86ec' does not provide an export named 'default'


I'm using Sveltekit and I upgraded chart.js from @2.9.4 to its latest version, upon upgrading I get the below error:

500
The requested module '/node_modules/.vite/deps/chart_js.js?v=425f86ec' does not provide an export named 'default'
SyntaxError: The requested module '/node_modules/.vite/deps/chart_js.js?v=425f86ec' does not provide an export named 'default'

I get above stated error as I import it as below:

import chartjs from 'chart.js';

I also get the same error in any version above [email protected].

Thank You.


Solution

  • Chart.js V3 is treeshakable so you need to import and register everything or if you want everything you need to import the chart from the auto import like so:

    import Chart from 'chart.js/auto';
    

    For more information about the different ways of importing and using chart.js you can read the integration page in the docs.

    Since you are upgrading from Chart.js V2 you might also want to read the migration guide since there are some major breaking changes between V2 and V3