32

I am using ng2-charts in Angular 7 app and having warning

WARNING in ./node_modules/ng2-charts/fesm5/ng2-charts.js 230:54-72 "export 'ɵɵdefineInjectable' was not found in '@angular/core'

error in VS Code

enter image description here

error in browser

enter image description here

What could be the reason and how to resolve it?

WasiF
  • 26,101
  • 16
  • 120
  • 128
  • What are you using ng2-charts in your code. Code you please update the code ? – Tony Ngo May 30 '19 at 04:02
  • I am using `ng2-charts`, `chart.js` and `@types/chart.js`. Code is posted but I think it is not related to code. It may be related to some `import` or `export` module – WasiF May 30 '19 at 04:09
  • 1
    May be because of version compatibility? have you tried out other versions? – samheihey May 30 '19 at 04:11
  • No, not yet. OK try to figure via different versions. Thanks for suggestion – WasiF May 30 '19 at 04:12
  • Thanks for your suggestion. It worked. version `2.2.4` was giving this error but `2.2.3` worked fine. – WasiF May 30 '19 at 04:30
  • 2
    Version `2.2.5` also works fine. – croc Jun 11 '19 at 15:04
  • @croc Surely they fixed that bug in that `2.2.5` – WasiF Jun 12 '19 at 03:12
  • 3
    I think they just reverted the changes from `2.2.4` ([bug report](https://github.com/valor-software/ng2-charts/issues/750)). Sadly this hasn't been fixed in `2.3.0` yet as well. – croc Jun 12 '19 at 19:18
  • 4
    I should have found this link earlier. This bug is in 2.3.0 as well. – ACB Aug 09 '19 at 11:44

2 Answers2

64

Update: May 2021

Recently I have used ng2-charts@2.4.2 in Angular v11 and it's working fine. You may try with the latest version

npm install ng2-charts@latest // it will automatically install latest version

Older

ng2-charts v2.2.4 has this bug as lots of users are reporting that so down-grading to ng2-charts v2.2.3 is fine until it is fixed in the future releases.

npm install ng2-charts@2.2.3
WasiF
  • 26,101
  • 16
  • 120
  • 128
  • 3
    Downgrading works fine. Just `npm install ng2-charts@2.2.3 --save` and wait for it to update – LuisMorais May 31 '19 at 13:52
  • @WasiF I have angular version 5.2.1, i tried above solution but it didn't work. Please guide – Ankur Raiyani May 05 '20 at 06:21
  • @WasiF It's same error as mentioned in above question. We tried with version 2.2.0, 2.2.3 & 2.2.5 but getting same error. We have Angular CLI 1.7 and angular core 5.2.1 – Ankur Raiyani May 06 '20 at 12:52
  • @AnkurRaiyani it might be the reason of angular version because if you read question of I have mentioned the angular version on 1st line that it is `Angular 7` – WasiF May 07 '20 at 11:12
  • Downgrading failed with this logs ```PS D:\projects\twit-auto\ui> npm install ng2-charts@2.2.3 npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name "__ngcc_entry_points__.json": name cannot start with an underscore``` – c.sankhala Jun 14 '21 at 13:57
2

Right, you have to do npm install ng2-charts@2.2.3 --save Also, check into your package.json for "ng2-charts": "2.2.3", I also faced same issue but previously I had "ng2-charts": "^2.2.3", so I removed caret (^). It means "Compatible with version" it will install major version. But use "Fixed version" if you don't want to change version of package on each installation.

Mayur Saner
  • 444
  • 5
  • 10