echarts-for-react icon indicating copy to clipboard operation
echarts-for-react copied to clipboard

Add tslib as dependency

Open MasterOdin opened this issue 3 years ago • 1 comments

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

MasterOdin avatar Oct 19 '22 13:10 MasterOdin

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

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

andresgutgon avatar Nov 29 '22 14:11 andresgutgon