Angular 6 cannot compile with `ng serve --prod`

monkeycon:
Angular 6 uses typescript. Unless echarts have exposed type definition (like .h header for C program), you will have compilation problem.

chfw:
I have the exact same issue,
Angular 6 will use the echarts using the "@ types/echarts" typings
The issue comes from webpack optimization so as a temporary fix you can run ng build --prod --build-optimizer=false and the project will compile (though this is not ideal).
Upon further research, I discovered that the issue seems to stem from the version of webpack being used by the angular cli (with cli version 6.0 + uses webpack 4.8.3)

"Whenever you see Cannot read property 'afterCompile' of undefined it probably means ts-loader is dealing with webpack 3 not webpack 4." - johnnyreilly (TypeStrong/ts-loader#729)


I'm still looking into the issue and trying to find a permanent fix but this is as far as I got so far.

dragonman117:
@pissang I'm unsure why this is marked as closed, is there a patch that is not mentioned here?

pissang:
@dragonman117 I just referenced another similar issue and closed that one. This issue will still be open and followed.

dragonman117:
For those seeking for a quick fix, removing @types/echarts allows to not remove the build optimizer.

pissang:
I found the fix for me as for now. Still it is a workaround, I cannot explain it, I cannot say it is very stable and the best solution forever but it is better than nothing.
All you need is to remap the path of the echarts to use the minified version of it. See example of the root tsconfig file:
```javascript { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", "paths": { "echarts": ["node_modules/echarts/dist/echarts.min.js"] }, "typeRoots": [ "node_modules/@types" ], "lib": [ "es2017", "dom" ] } } ``` With this you can still use the typings and enjoy the AOT build. Actually the build became a bit faster (IMO)

wartab:
I got this error after updating ngx-echarts to version 4.0.0. Downgrading to 3.2.0 solved the issue for me.
It's working fine when using this combination of packages:
"@angular-devkit/build-angular": "^0.6.8",
"@types/echarts": "0.0.13",
"echarts": "^4.1.0",
"ngx-echarts": "^3.2.0"

Update
After updating all packages to @latest, it's working fine too:
"@angular-devkit/build-angular": "^0.7.4",
"@types/echarts": "^4.1.0",
"echarts": "^4.1.0",
"ngx-echarts": "^4.0.0"

smnbbrv:
Not work after angular7
原文地址:https://github.com/apache/incubator-echarts/issues?utf8=%E2%9C%93&q=TypeError&page=4