antvis/G2



The issue has been closed
require() of ES Module Error when Using @antv/g2 with Vitest #6486
222chaos posted onGitHub
问题描述
在使用 @antv/g2 库时,遇到了以下错误: Error: require() of ES Module /path/to/project/node_modules/d3-array/src/index.js from /path/to/project/node_modules/@antv/g2/lib/transform/utils/order.js not supported. Instead change the require of index.js in /path/to/project/node_modules/@antv/g2/lib/transform/utils/order.js to a dynamic import() which is available in all CommonJS modules.
重现链接
No response
重现步骤
1.使用 vitest 进行单元测试。
2.项目中引入了 @ant-design/plots 和 @ant-design/charts。
3.运行测试时,报错与 @antv/g2 依赖 d3-array 模块不兼容。
预期行为
@antv/g2 应该能够正确处理 ES 模块的导入,避免使用 require() 导入 ES 模块,改为使用 import() 来确保兼容性。
平台
No response
屏幕截图或视频(可选)
No response
补充说明(可选)
可能的解决方案是将 require() 替换为动态 import(),以兼容 ES 模块环境。