xieziyu / ngx-echarts

An angular (ver >= 2.x) directive for ECharts (ver >= 3.x)
https://xieziyu.github.io/ngx-echarts/
MIT License
1.11k stars 197 forks source link

ERROR TypeError: e.echarts is null when ng build is executed in production mode #243

Open niijyeni opened 4 years ago

niijyeni commented 4 years ago

@types/echarts 4.6.2 ngx-echarts 5.0.0 echarts 4.8.0 angular 8.3.26

FonsecaJoao commented 4 years ago

241 Possible solution

lundmikkel commented 4 years ago

Could this issue get some attention?

vishnu-dev commented 4 years ago

Really need a solution for this. Please help @xieziyu.

The below workaround seems to work, but need a concrete solution,

import {init} from 'echarts';

Module import should be like

NgxEchartsModule.forRoot({echarts: {init}})

Also, Production build works only without the Ahead of time compiler.

ng build --prod
lundmikkel commented 4 years ago

Agree, @vishnu-dev. Though we've used your solution previously, it broke the types system for projects consuming an npm package with ECharts and @types/echarts. We've gone back to downgrading ngx-echarts to version 4.2.1. Haven't encountered any problems with that yet.

lundmikkel commented 4 years ago

@xieziyu Does this have no interest to you? It's been more than a month since the last comment, and there are multiple issues that all complain about this particular bug. You don't seem to reply to any of them, even when you are tagged. Is this package one we can trust in, or should we start searching for others?

xieziyu commented 4 years ago

@lundmikkel SORRY for the late reply. I fail to reproduce this issue in my projects. Could you help to setup a minimal reproduction environment or a repo? That would be great helpful to fix this issue.

vishnu-dev commented 4 years ago

@xieziyu This is the config as mentioned by OP.

@types/echarts 4.6.2 ngx-echarts 5.0.0 echarts 4.8.0 angular 8.3.26

Also, ensure your global angular version is the same as the above i.e. ng --version should give 8.3.26

pierrebonny commented 4 years ago

Please help, this issue is really annoying Angular 8.2.3 ngx-echarts 5.1.1 echarts 4.7.0

xieziyu commented 4 years ago

@pierrebonny @vishnu-dev

This should work

// replace import * as echarts from 'echarts';
export function echarts() {
  return import('echarts');
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxEchartsModule.forRoot({
      echarts,
    }),
  ],
  providers: [],
  bootstrap: [AppComponent]
})
pierrebonny commented 4 years ago

@xieziyu thanks for the answer but I am trying to custom build echarts thanks to your readme. How should i fix the problem as I use an external custom-echarts.ts file as explained in the readme ?

Thanks

huu8 commented 4 years ago

@pierrebonny @vishnu-dev

This should work

// replace import * as echarts from 'echarts';
export function echarts() {
  return import('echarts');
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxEchartsModule.forRoot({
      echarts,
    }),
  ],
  providers: [],
  bootstrap: [AppComponent]
})

it is doesn't work

pierrebonny commented 4 years ago

@xieziyu thanks for the answer but I am trying to custom build echarts thanks to your readme. How should i fix the problem as I use an external custom-echarts.ts file as explained in the readme ?

Thanks

Can someone help on this issue ? thx

javkhaanj7 commented 4 years ago

@pierrebonny I had same issue too on custom build. The above answer https://github.com/xieziyu/ngx-echarts/issues/243#issuecomment-688818402 actually solves the issue in my case. You could try this:

Angular: 8.0.2 echarts: ^4.9.0, ngx-echarts: ^5.1.2

custom-echarts.ts

export * from 'echarts/src/echarts';

import 'echarts/src/chart/line';

import 'echarts/src/component/title';
import 'echarts/src/component/tooltip';

[your].module.ts

..
import { NgxEchartsModule } from 'ngx-echarts';
..
export function echarts() {
  return import('./custom-echarts');
}
..
@NgModule({
  ..
  imports: [
    ..
    NgxEchartsModule.forRoot({
      echarts
    }),
    ..
  ]
})
export class [Your]Module { }
weiwan-gmail commented 4 years ago

The solution doesn't work when ngx-echarts is packed again in another Angular lib.

ng build xxxlib

ERROR: xxx.module.ts:36:1: Error encountered in metadata generated for exported symbol 'XxxxxModule': xxxx.module.ts:33:10: Metadata collected contains an error that will be reported at runtime: Expression form not supported. {"symbolic":"error","message":"Expression form not supported","line":32,"character":9} An unhandled exception occurred: XXXX.module.ts:36:1: Error encountered in metadata generated for exported symbol 'XxxxxModule': Metadata collected contains an error that will be reported at runtime: Expression form not supported. {"symbolic":"error","message":"Expression form not supported","line":32,"character":9}

pierrebonny commented 3 years ago

Did someone find a solution for this issue ? @xieziyu any idea ? thx

Emanuele-Moolan commented 3 years ago

Every other solutions worked only on locally for me , But this one really fixed the build even in aws-prod

// replace import * as echarts from 'echarts';
export function echarts() {
  return import('echarts');
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxEchartsModule.forRoot({
      echarts,
    }),
  ],
  providers: [],
  bootstrap: [AppComponent]
})