next.js 使用 antv [email protected] 报错 Error [ERR_REQUIRE_ESM] #5089
-
next.js 使用 antv [email protected] 报错:
应该是d3-interpolate升级导致的。 |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 3 replies
-
package.json 中指定d3-interpolate版本可暂时解决 "resolutions": {
"d3-interpolate": "2.0.1"
}, |
Beta Was this translation helpful? Give feedback.
-
对于 next.js 项目,在package.json中添加 "type":"module", 并将项目中所有用require()的地方改为import即可。可参考:https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c |
Beta Was this translation helpful? Give feedback.
-
然后报错原因是因为 "exports": {
"umd": "./dist/d3-interpolate.min.js",
"default": "./src/index.js"
}, 所以有两个解法: |
Beta Was this translation helpful? Give feedback.
-
官方没有解决方法吗? |
Beta Was this translation helpful? Give feedback.
-
Is anyone able to use antv with antd, react, and next.js? Getting a simple line chart throws all of these ES module d3-interpolate errors above. I don't think antv has been updated since July. |
Beta Was this translation helpful? Give feedback.
-
使用最新版 next.js 13.4.3 和 g2 5.0.9 该问题依然存在,在 package.json 中指定 d3-interpolate 版本虽然能解决但又会报错 next.js 官方文档对此报错给出的解决方法是 https://nextjs.org/docs/messages/import-esm-externals |
Beta Was this translation helpful? Give feedback.
-
关于 d3-interpolate 在 next 中的报错,也欢迎大家去 d3-interpolate 的 issue 中提交问题。这个问题需要他们官方去解决。 |
Beta Was this translation helpful? Give feedback.
-
nextjs和remix官方的临时解决方法我这边不生效 这个问题不出在D3那边,D3只是切换到了ESM而已 这个问题应该算是g2和nextjs/remix的兼容问题 引入 我这边的临时解决方法是把导入g2放入到useEffect里
感觉这个问题其实还是应该g2这边来处理,对nextjs/remix进行兼容 参考: |
Beta Was this translation helpful? Give feedback.
package.json 中指定d3-interpolate版本可暂时解决