Open
Description
I have tried the new v5.0.0 with Angular 9
configuration:
- Angular v 9.1.0
- ngx-echarts v5.0.0
- echarts v4.8.0
And I get the following error:
core.js:6185 ERROR TypeError: Cannot read property 'init' of null
I see this comes from the line:
return this.ngZone.runOutsideAngular(() => this.echarts.init(dom, this.theme, this.initOpts));
where this.echarts
is null
.
I tried to modify the newly added .forRoot() in the app.module.ts with instructions from #236 and #237. This did not help.
Activity
ICTlight commentedon Jun 23, 2020
deal??
cray2015 commentedon Jun 23, 2020
the workaround for this issue is to downgrade echarts for the time being.
These version worked for me in the production environment along with Angular 9
Reda1000 commentedon Jun 24, 2020
Can confirm - upgraded Angular yesterday and found echarts missing today in production build via
ng build --prod
.Allthough using
ng serve
it does display charts correctly.FonsecaJoao commentedon Jun 29, 2020
For those who want to apply this workaround, it is worth mentioning that the import in appModule needs to be like this:
instead of this:
cray2015 commentedon Jun 30, 2020
Yes my bad. The only reason I did not mention that is because the build will give error if you still use forRoot, also the previous version of ngx-echarts never had forRoot so I thought it was self explanatory. :)
lundmikkel commentedon Jun 30, 2020
I seem to have found a fix for this, when using version 5.0.0. As far as I can see, the problem arises with AOT (ahead-of-time compilation) being used. The dependency gets optimized away, somehow. The trick is to rewrite the import like this:
Not quite sure why it works, however.
lundmikkel commentedon Jul 1, 2020
This actually seems to cause type problems elsewhere, so might not really be a solution after all.
VitalyName commentedon Dec 10, 2020
I solved it in my application. I make this steps:
Delete import
import * as echarts from 'echarts';
Add function with import to app.module.ts
Arberto99 commentedon Dec 6, 2021
Useful, but found a better fix for the import in module:
without any function in app.module.ts, so the code is cleaner. :)
BhagyashreeCH commentedon Feb 6, 2023
I have recently upgraded angular 7 to 9 even after tried to update multiple versions of ngx-echarts and echarts versions I was getting NgxEchartsConfig is null error, finally i was able to fix with your solution as mentioned above.
Angular: 9.1.13
"echarts": "^4.9.0",
"ngx-echarts": "^6.0.0",
NgxEchartsModule.forRoot({
echarts: { init: echarts.init }
})
Thank you sir lundmikkel...
rickynguyenc commentedon Apr 27, 2023
Thanks you so much, It work for me