Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复动态导入esm模块时,ecStat.transform.histogram为空导致图表不显示的错误 #4904

Closed
wants to merge 1 commit into from

Conversation

iceqing
Copy link
Contributor

@iceqing iceqing commented Jul 17, 2022

当模块采用esm时,由于动态import ecStat,但是未使用default,导致ecStat为模块,ecStat.transform.histogram为空,会出现如下错误导致图表无法展示:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'regression')
    at ChartRenderer.<anonymous> (Chart.js:147:76)
    at step (tslib.es6.js:102:23)
    at Object.next (tslib.es6.js:83:53)
    at tslib.es6.js:76:71
    at new Promise (<anonymous>)
    at __awaiter (tslib.es6.js:72:12)
    at Chart.js:128:24

正常代码应该为
ecStat.default.transform.histogram,所以在动态导入后, 添加default属性判断,如果default不为空,将default属性赋值给ecStat对象。

修改后的react-amis-admin示例代码,采用patch-package临时修复:
https://github.com/iceqing/react-amis-admin/tree/vite

amis ecStat默认未使用default错误示例代码, amis-esm-demo 项目:
https://github.com/iceqing/amis-esm-demo

image

正常的页面展示效果(分支为vite),可以参考示例网站 https://amis.iceq.cc/

@github-actions github-actions bot added the fix label Jul 17, 2022
@github-actions
Copy link

👍 Thanks for this!
🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

@iceqing
Copy link
Contributor Author

iceqing commented Jul 17, 2022

相关issue:
#3908
iceqing/react-amis-admin#3

@iceqing iceqing changed the title fix: 修复动态导入esm模块时,ecStat为模块导致ecStat.transform.histogram为空导致的错误 fix: 修复动态导入esm模块时,ecStat.transform.histogram为空导致图表不显示的错误 Jul 17, 2022
@iceqing iceqing closed this by deleting the head repository Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant