-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
X6并不支持服务端渲染 #4095
Comments
Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. |
我也遇到这个问题 |
怎么close了 nuxt上 还是报错 ESM |
@yoke233 其实不应该close,因为我的PR只是解决了一部分问题。当然现在已经可以在nuxt上用了,但需要transpile这个库: export default defineNuxtConfig({
build: {
transpile: [
/^@antv/,
'gl-matrix',
],
}
}) 我会再开一个issue追踪剩余的问题。 |
我直接 reopen 吧。 |
其他可视化相关开源库:
|
在Nuxt3中,加上了这段transpile,还是不能用, g6版本已经是5.0.18了 |
Describe the bug
初次尝试X6,在SSR项目中引入X6,会报错,如:
目前我发现的在
@antv/x6-common
的polyfill.ts
和prefix.ts
中,使用了很多document
和Element
,这俩只有在browser端才有,服务端Node.js是没有的,所以就出错了。比较奇怪的是js的polyfill和css的prefix通常应该由下游用户自主决定,比如根据想要兼容的浏览器版本使用webpack/vite来transpile code, 然后用babel来加垫片,postcss来处理css兼容问题。直接在库里处理浏览器兼容问题不是良好的实践,会引入很多不需要代码增加体积。
另外一个比较大的问题是没有有效的ESM入口,也和服务端渲染有关,Node.js不认
package.json
中的module
,必须要用exports
表明ESM的入口。参考这两个网站https://publint.dev/@antv/[email protected]
https://arethetypeswrong.github.io/?p=%40antv%2Fx6%402.16.1
可以看到X6只有CJS入口,没有能被识别的ESM入口。
正确的写法应当如下:
或指定
type: "module"
参考:
https://publint.dev/rules#has_module_but_no_exports
https://nuxt.com/docs/guide/concepts/esm#what-are-valid-imports-in-a-nodejs-context
Your Example Website or App
https://stackblitz.com/edit/github-h7fojp
Steps to Reproduce the Bug or Issue
在SSR项目中引入X6
Expected behavior
根据README,X6应该是支持服务端渲染的,不应该有这样的问题。
X6/README.md
Line 32 in f2cae96
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: