Ng2-charts: ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function

Created on 5 Jun 2019  路  19Comments  路  Source: valor-software/ng2-charts

Reproduction of the problem

ng2-charts is a port & modification of Chart.js component for Angular 2. Sometimes the issue is related to Chart.js instead of ng2-charts.
To confirm, if the issue shows in a pure Chart.js project, it is an issue of Chart.js.
Pure Chart.js starting template: https://jsfiddle.net/Hongbo_Miao/mvct2uwo/3/

If the issue does not show in a pure Chart.js project and shows in an
Screenshot from 2019-06-05 13-27-55
the ng2-charts project, please try to provide a minimal demo of the problem.
ng2-charts starting template: http://plnkr.co/edit/Ka4NXG3pZ1mXnaN95HX5?p=preview

Most helpful comment

i think it like #1115.
try npm install ng2-charts@~2.2.5, and run agian

All 19 comments

The same issue

i think it like #1115.
try npm install ng2-charts@~2.2.5, and run agian

Hi,

I have ng chart in production and I am facing the same issue. Can somebody suggest for solutions asap.
_

with me, i edit code in ./node_modules/ng2-charts/fesm5/ng2-charts.js find and replace 傻傻defineInjectable to defineInjectable. It's working with me, but i don't want edit lib, can you update lib?

same error.

i am also facing this error. anyone got the solution?

same issue here too.any appropriate fix aside editing 傻傻defineInjectable in library?

i used the older release 2.2.0 and the issue is not coming there. earlier i was using 2.2.4 version. I have not tried 2.2.5.
For now my code is working with 2.2.0 version

I just realized any version <=2.2.3 works.
So just open package.json and update ng2-charts version accordingly.

2.2.5 works for me.

npm install ng2-charts@~2.2.5 --save works for me

I agree with @tranvannhat , I also edit the code in ./node_modules/ng2-charts/fesm5/ng2-charts.js and replace 傻傻defineInjectable to defineInjectable and it's working fine. ng2-chart team can you update this? As we are using this lib in prod and while building on prod I cannot push my local lib. it will fetch from repo.

For me issue is with Angular 7.

As a few folks have noted, I was able to update to v2.2.5 and this issue was fixed in an Angular 7 project:

npm install [email protected] --save

The error popped up after there was a change to build this project (ng2-charts) with Angular 8. That change was reverted with Release v2.2.5: https://github.com/valor-software/ng2-charts/releases/tag/2.2.5

v2.3.0 has been upgraded to use Angular 8 or Angular 7 (so it should - in theory - also work): https://github.com/valor-software/ng2-charts/commit/ec5e6038ae4d1a94737340b00397175324491028#diff-e86dda6566477895fbf685c476288762

Angular's official repo has an issue on this type of error if you're interested: https://github.com/angular/angular/issues/30413

@bryplano I've just updated ng2-charts to v2.3.0 on an Angular 8 project and this error popped up as well.

@rcrodrigues thanks for checking! Shame the change broke this (and other) libs, but it sounds like it's intended per this post: https://github.com/angular/angular/issues/30413#issuecomment-491683547

Given all the above, I don't see how this issue is actionable, so I'll go ahead and close this. My advise would be to keep building your library using the minimally required Angular version.

Guess sticking at 2.2.5 is currently advisable @rcrodrigues :\

For those interested, upgrading my app to Angular v8 and using ng2-charts v2.3.0 fixes this issue for me.

As indicated in the helpfully linked angular/angular#30413, this issue was caused by compiling this library using the Angular v8 compiler. Libraries which support either Angular v7 || v8 must be compiled using angular v7.

cc: @bryplano - pinging you because it sounds like you might be interested to know that ng2-charts v2.3.0 can (does?) work with the latest version of Angular v8 (v8.0.3 as of writing).

I am also facing the same issue I upgrade to 2.2.5 ng serve works fine but ng build it is showing the same error "Uncaught TypeError: Object(...) is not a function" any one help asap.

Curious - why are you using an older version? Current version is 2.4.2

I just created a fresh angular app using @angular/cli@^8.0.0 and imported ChartsModule from [email protected] - no problems. It's not the angular version, or the library... something else in your setup is the issue.

Stackblitz example https://stackblitz.com/edit/ng2-charts-angular-8

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shyamal890 picture shyamal890  路  4Comments

Adwind picture Adwind  路  3Comments

mrpotato3 picture mrpotato3  路  5Comments

alexcastillo picture alexcastillo  路  5Comments

egervari picture egervari  路  4Comments