antvis/G6

require() of ES Module not supported #4646

sunface posted onGitHub

Describe the bug

你好,我在nextjs + react18 + typescript的环境下,使用时报如下错误,无论如何都解决不了,最后只能把对应的 require 屏蔽掉。

Error: require() of ES Module /Users/sunfei/development/MyStarship/starship/ui/node_modules/d3-interpolate/src/index.js from /Users/sunfei/development/MyStarship/starship/ui/node_modules/@antv/g-base/lib/animate/timeline.js not supported. Instead change the require of index.js in /Users/sunfei/development/MyStarship/starship/ui/node_modules/@antv/g-base/lib/animate/timeline.js to a dynamic import() which is available in all CommonJS modules.

Your Example Website or App

null

Steps to Reproduce the Bug or Issue

null

Expected behavior

null

Screenshots or Videos

No response

Platform

  • OS: [macOS]
  • Browser: [Chrome, safari]
  • Version: [e.g. 91.1]

Additional context

No response


我写了一个 next + react18 + G6 的例子,并没有出现报错: https://stackblitz.com/edit/nextjs-df4m2f?file=pages%2Findex.js

方便提供更详细的复现例子吗?

posted by xiaoiver almost 2 years ago

我对照下你的例子,试试先,感谢兄弟 :D

posted by sunface almost 2 years ago

你好,我感觉像是 typescript 的问题,你可以试试编译运行我的项目 : https://github.com/datavisions/datav ui 目录下, npm run dev 运行,不用启动服务器端也可以复现报错( 不启动服务器端,没有 UI 画面)

posted by sunface almost 2 years ago

我也复现这个问题了: <img width="451" alt="截屏2023-06-16 上午10 16 15" src="https://github.com/antvis/G6/assets/3608471/e8497ca6-d9ef-427a-9dc6-da90ab88581c">

posted by xiaoiver almost 2 years ago

可以参考 G2 之前的解决办法: https://github.com/antvis/G2/issues/4493#issuecomment-1562328100

原因是我们使用的 d3-interpolate 3.x 有些问题,但使用 2.x 又会有 snyk 问题。因此可以暂时先强行指定安装 2.x 版本:

// package.json
"overrides": {
  "d3-interpolate": "2.0.1"
}

我又更新了下上面 stackblitz 的例子,现在不会报错了供您参考: https://stackblitz.com/edit/nextjs-df4m2f?file=next.config.js,package.json%3AL19,.babelrc

posted by xiaoiver almost 2 years ago

好的,好的,我晚一些试试,非常感谢~~ 辛苦了

posted by sunface almost 2 years ago

试了下,可以了 :) 那使用旧版本的这个解决方案会影响哪个方面?我提前做好心理准备

posted by sunface almost 2 years ago

试了下,可以了 :) 那使用旧版本的这个解决方案会影响哪个方面?我提前做好心理准备

d3-interpolate 2.x 依赖 d3-color 2.x,该版本存在安全漏洞: https://security.snyk.io/vuln/?search=d3-color

另外我以前在知乎看到过您写的关于 Rust 的文章,我最近也在学习,在 @antv/layout 和 algorithm 里实现了一些简单的布局和分析算法,以后可以多交流哈。

posted by xiaoiver almost 2 years ago

好的,好的,谢谢兄弟,以后有机会可以多交流

posted by sunface almost 2 years ago

对了,这个项目真的很棒,产品体验和性能都很强!

posted by sunface almost 2 years ago

Fund this Issue

$0.00
Funded

Pull requests