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

3

7

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.

Darmit answered 15/11, 2022 at 11:19 Comment(3)
react-chartjs-2 has specific version dependencies with chart.js. Have you looked at the dependency guide in the docs? react-chartjs-2.js.org/docs/chartjs-v2 You may need to use a combination like chart.js@^3.6.0 react-chartjs-2@latestPohai
thanks for the information but this won't work I tried it.Darmit
I have that with Chart.js 4 (Vue.js but not the vue chartjs package though). Chart.js 3 is working fine for mePyridoxine
L
0

For module bundling frameworks often use tools like Webpack or Rollup. Your current version of bundling tool may not support static properties. So you will need to update your webpack version or you may have to use babel/preset-env configuration.

The other solution is to downgrade Chart.js version. You can go with Chart.js v3.x.x

Lacey answered 16/3 at 16:26 Comment(0)
E
7

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.

Emmyemmye answered 24/11, 2022 at 11:16 Comment(1)
Thank you for your help, yeah I used this and it worked.Darmit
G
2

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

Grass answered 13/12, 2022 at 6:52 Comment(0)
L
0

For module bundling frameworks often use tools like Webpack or Rollup. Your current version of bundling tool may not support static properties. So you will need to update your webpack version or you may have to use babel/preset-env configuration.

The other solution is to downgrade Chart.js version. You can go with Chart.js v3.x.x

Lacey answered 16/3 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.