问题描述
我在使用 chartJS 和 primeNG 时遇到此错误:
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)
在我的 angular.json 文件中,我添加了:脚本":[node_modules/chart.js/dist/Chart.js"]
in my angular.json file I have added the:"scripts": ["node_modules/chart.js/dist/Chart.js"]
ChartJS 版本:chart.js":^3.0.2",PrimeNG:primeng":^11.3.2",Angular CLI v:@angular/cli":~10.0.1",
ChartJS version: "chart.js": "^3.0.2",PrimeNG : "primeng": "^11.3.2",Angular CLI v : "@angular/cli": "~10.0.1",
推荐答案
自本月v3刚刚发布以来,高概率primeng仍然只适用于chart.js的v2,并且有一些突破性的变化.
High probability primeng still only works with v2 of chart.js since v3 just released this month and had some breaking changes.
将chart.js 降级到2.9.4 版应该可以解决您的问题
Downgrading chart.js to version 2.9.4 should resolve your issue
这篇关于core.js:4197 错误类型错误:chart_js__WEBPACK_IMPORTED_MODULE_2__ 不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!