chartjs-adapter-date-fns icon indicating copy to clipboard operation
chartjs-adapter-date-fns copied to clipboard

chart.min.js:13 Uncaught SyntaxError: Cannot use import statement outside a module (at chart.min.js:13:1)

Open AlizerUncaged opened this issue 1 year ago • 1 comments

i get this error whenever i add

<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
``` in my code

chart.min.js:13 Uncaught SyntaxError: Cannot use import statement outside a module (at chart.min.js:13:1)

AlizerUncaged avatar Sep 02 '23 07:09 AlizerUncaged

Chart.js v4 doesn't include chart.min.js in dist, but jsDelivr returns the auto-generated minified version of chart.js which is the ESM file in v4, so this causes the error above. You can use the UMD file as follows:

<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>

Or, simply:

<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@3"></script>

nagix avatar Jan 10 '24 09:01 nagix