Module ''chart.js'' has no exported member 'Chart'

I am porting my JS project over to TS and the Chart.js import is giving trouble. I did

npm install chart.js --save

And in my .ts file:

import {Chart} from 'chart.js'

For awhile i was stuck with Cannot find module 'chart.js' and the app would not start up. I somewhat followed Mike Hartington’s external library guide (--ambient is deprecated?) and now have the error Module ''chart.js'' has no exported member 'Chart'

tsconfig
image

package.json
image

Right, chartjs is not exporting a Chart class.

So what you can do is try this.

import * as chart from 'chart.js';

This will give you reference to the global chart API, which is what is being exporting.

Great, that fixed the error. But how can I now access a given class using this global API?

For example,

var plot = new Chart(ctx, {
    type: 'line',
    ...
    });

obviously has no idea what Chart is anymore, so I presumably have to access it from the import.

you’d do

// notice the lower chase chart
var plot  = new char(ctx, {}

Just fixed it. That’s what I thought it would be, turns out the problem was with my canvas type.

let canvas: any = document.getElementById("chart");
let ctx = canvas.getContext("2d");
var plot = new chart(ctx, {
    type: 'line',
    ...
    });

Thanks very much!

Prefer @ViewChild to calling DOM methods on document.