hustcc / echarts-for-react

⛳️ Apache ECharts components for React wrapper. 一个简单的 Apache echarts 的 React 封装。
https://git.hust.cc/echarts-for-react
MIT License
4.56k stars 634 forks source link

Add tslib as dependency #512

Open MasterOdin opened 2 years ago

MasterOdin commented 2 years ago

Making an issue for this seeing as how #494 was closed without comment.

This library enables the importHelpers option in the tsconfig.json:

https://github.com/hustcc/echarts-for-react/blob/a35220e42c18b5f1714e31f61a8ba0f7f2f27334/tsconfig.json#L10

Per the tsconfig docs, when using this option, the tslib module must be available to be imported at runtime. However, this library does not include tslib as a dependency, and instead relies that tslib will be available from another dependency at the top of the node_modules folder. The echarts peer dependency does include tslib as its own dependency, but depending on how the package manager decides to hoist, it may or may not be available, and so can lead to this module unexpectedly not working. This is happening to me in a monorepo and so we are using a fork of this library that adds tslib, an alternative would be that we need to install tslib in our package.json file.

This is similar to an issue echarts itself ran into last year: https://github.com/apache/echarts/pull/13573

andresgutgon commented 1 year ago

I solved this issue by importing the esm version like this:

import Echart from 'echarts-for-react/esm/core.js`