Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

./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.

like image 443
Tanya Singh Avatar asked Jul 28 '26 09:07

Tanya Singh


2 Answers

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

npm i --save [email protected]

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

like image 82
pizzaboy Avatar answered Jul 30 '26 22:07

pizzaboy


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

like image 36
Thamjith Thaha Avatar answered Jul 31 '26 00:07

Thamjith Thaha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!