Invalid module name in augmentation. Module 'chart.js' resolves to an untyped module at '/src/chart.js', which cannot be augmented

Shriniwas b picture Shriniwas b · Mar 29, 2019 · Viewed 6.9k times · Source

I'm creating barchart using ng2-chart library for charts. I got the following error while ng serve:

ERROR in node_modules/chartjs-plugin-datalabels/types/index.d.ts(5,16): error TS2665: Invalid module name in augmentation. Module 'chart.js' resolves to an untyped module at '/node_modules/chart.js/src/chart.js', which cannot be augmented.

I want some datalabels on barchart.

So I added 'chartjs-plugin-datalabels' in component.

When I add following lines in my code, this error occurs.

import * as pluginDataLabels from 'chartjs-plugin-datalabels';

export class AnalysisComponent implements OnInit {
    public barChartPlugins = [pluginDataLabels];
}

Version of libraries

"chart.js": "^2.7.3",
"ng2-charts": "^1.6.0",
"chartjs-plugin-datalabels": "^0.6.0",

Any help will be appreciated.

Answer

Michael Fagundes Marques picture Michael Fagundes Marques · Mar 29, 2019

Per this comment you have to install @types/chart.js. And you have to import this lib with

import * as Chart from 'chart.js';