简体   繁体   中英

./node_modules/chart.js/dist/chart.js 695:18 Module parse failed: Unexpected token (695:18)

After running 'npm start' on my localhost, I am getting the following error:

./node_modules/chart.js/dist/chart.js 695:18 Module parse failed: Unexpected token (695: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;

I have updated versions of chart.js, react chartjs 2. I remove node_modules and package-lock.json and reinstall, the app not started. I've removed node_modules/package-lock.json/clear npm cache. Doesn't help.

Your project is very probably compiled for version of TypeScript which is incompatible with the v4 of chart.js I resolved my issues by installing version 3, you can use this command:

npm i --save chart.js@3.9.1

The best option would probably be to update all the libs and TypeScript configurations, so that you could use the v4.

We have to use specific versions of chart.js and react-chartjs-2.

For chart.js v2:

npm install --save chart.js@^2.9.4 react-chartjs-2@^2.11.2

For chart.js v3:

npm install --save chart.js@^3.6.0 react-chartjs-2@^4.0.0

Also make sure to restart server after installing the package.

Refer here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM