Search code examples
angularchart.jsangular6

How to fix ERROR in node_modules/chart.js/types/animation.d.ts(20,37): error TS1005: ',' expected. in chart.js


I am working on an Angular 6 project where I want to create some charts using chart.js.

I installed chart.js using npm install chart.js and its version is like 3.5.1.

My TypeScript version is like 2.9.0.

So when I try to ng serve:

node_modules/chart.js/types/animation.d.ts(20,37): error TS1005: ',' expected.
node_modules/chart.js/types/animation.d.ts(20,46): error TS1005: ',' expected.
node_modules/chart.js/types/index.esm.d.ts(39,56): error TS1005: ';' expected.
node_modules/chart.js/types/index.esm.d.ts(39,58): error TS1011: An element access expression should take an argument.
node_modules/chart.js/types/index.esm.d.ts(39,85): error TS1005: '(' expected.
node_modules/chart.js/types/index.esm.d.ts(535,38): error TS1005: ',' expected.
node_modules/chart.js/types/index.esm.d.ts(535,56): error TS1005: ',' expected.
node_modules/chart.js/types/index.esm.d.ts(2424,37): error TS1005: ',' expected.
node_modules/chart.js/types/index.esm.d.ts(2424,50): error TS1005: ',' expected.
node_modules/chart.js/types/index.esm.d.ts(2734,63): error TS1005: ';' expected.
node_modules/chart.js/types/index.esm.d.ts(2734,69): error TS1011: An element access expression should take an argument.
node_modules/chart.js/types/index.esm.d.ts(2738,22): error TS1011: An element access expression should take an argument.
node_modules/chart.js/types/index.esm.d.ts(2742,63): error TS1005: '(' expected.
node_modules/chart.js/types/index.esm.d.ts(2746,57): error TS1005: '(' expected.
node_modules/chart.js/types/index.esm.d.ts(2746,68): error TS1005: ',' expected.
node_modules/chart.js/types/index.esm.d.ts(2746,75): error TS1011: An element access expression should take an argument.
node_modules/chart.js/types/index.esm.d.ts(2746,76): error TS1005: ')' expected.
node_modules/chart.js/types/index.esm.d.ts(2763,26): error TS1011: An element access expression should take an argument.
node_modules/chart.js/types/index.esm.d.ts(2767,67): error TS1005: '(' expected.
node_modules/chart.js/types/index.esm.d.ts(2771,56): error TS1005: '(' expected.
node_modules/chart.js/types/index.esm.d.ts(2771,67): error TS1005: ',' expected.
node_modules/chart.js/types/index.esm.d.ts(2771,73): error TS1011: An element access expression should take an argument.
node_modules/chart.js/types/index.esm.d.ts(2771,74): error TS1005: ')' expected.
node_modules/chart.js/types/index.esm.d.ts(2788,1): error TS1128: Declaration or statement expected.

What is this and how to fix this?

Thanks


Solution

  • As others have stated, downgrading to chart.js version 2.7.3 fixed this for me. For anyone not super familiar with npm, here's the commands I used to update the package:

    npm remove chart.js --save
    npm install chart.js@2.7.3 --save
    

    I specifically did this for my ionic 5 project. But it should also work for angular.