Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

core.js:4197 ERROR TypeError: chart_js__WEBPACK_IMPORTED_MODULE_2__ is not a constructor

I am having this error with chartJS and primeNG:

ERROR TypeError: chart_js__WEBPACK_IMPORTED_MODULE_2__ is not a constructor
    at UIChart.initChart (primeng-chart.js:48)
    at UIChart.ngAfterViewInit (primeng-chart.js:29)
    at callHook (core.js:3038)
    at callHooks (core.js:3008)
    at executeInitAndCheckHooks (core.js:2960)
    at refreshView (core.js:7243)
    at refreshComponent (core.js:8326)
    at refreshChildComponents (core.js:6965)
    at refreshView (core.js:7222)
    at refreshEmbeddedViews (core.js:8280)

in my angular.json file I have added the: "scripts": ["node_modules/chart.js/dist/Chart.js"]

ChartJS version: "chart.js": "^3.0.2", PrimeNG : "primeng": "^11.3.2", Angular CLI v : "@angular/cli": "~10.0.1",

like image 765
CodeCodeCodon Avatar asked Apr 08 '21 16:04

CodeCodeCodon


1 Answers

High probability primeng still only works with v2 of chart.js since v3 just released this month and had some breaking changes.

Downgrading chart.js to version 2.9.4 should resolve your issue

like image 78
LeeLenalee Avatar answered Nov 12 '22 13:11

LeeLenalee