Chart.js:使用最新版本的chart.js时模块解析失败

vc6uscn9  于 2022-11-29  发布在  Chart.js
关注(0)|答案(1)|浏览(481)

我已经安装了Chart.js v4.0.1,以便在我的react项目中使用,当我尝试导入chart.js模块时,如下所示:

import Chart from 'chart.js/auto'

它在我的终端中显示了一个错误,说模块的解析失败了。

./node_modules/chart.js/dist/chart.js 554:18
Module parse failed: Unexpected token (554:18)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| };
| class DatasetController {
>   static defaults = {};
|   static datasetElementType = null;
|   static dataElementType = null;

发生这种情况是因为我的节点模块中有一些过时的包,而最新的chart.js版本仍然是如此的边缘,以至于它需要一点解决方案才能工作?

1bqhqjot

1bqhqjot1#

这是因为您可能正在使用wepack 4,它不支持静态属性,所以您需要更新到webpack 5,或者使用babel/preset-env配置和babel加载程序来传输它

相关问题