I've been having trouble getting chart.js to import properly in a CommonJS application.
From what I can see with the docs all that seems to be required to use Chart.js with CommonJS is to simply run:
var Chart = require('chart.js');
var myChart = new Chart(ctx, {...});
However, when I run this I receive the error: "Chart is not a constructor".
Inspecting the Chart object, it appears that all the modules are saved in the Chart object as properties. No big deal, I was able to get it to reference properly by doing the following:
var chartjs = require('chart.js');
chartjs.Chart.register(
chartjs.whatever...
);
var myChart = new chartjs.Chart(ctx, {...});
Essentially mixing the way shown on how to tree shake with ESModule imports and CommonJS.
My question is really more or less is there something that I did incorrectly during setup such that the code provided in the documentation doesn't actually work? Or is it simply that the documentation may be out of date?
As for my setup I simply just installed the most recent version of Chart.js (currently 3.5.1) from npm.