antvis/G6

The issue has been closed
使用 vite 的 build.rollupOptions.output.manualChunks 配置自定义块分割,当 @antv/g2 和 @antv/g6 不在同一个块中时,打包后运行时报错。 #5469
pfdgithub posted onGitHub
问题描述
vite@5.1.4 @antv/g2@4.2.10 @antv/g6@4.8.24
// vite.config.js
const chunks = {
...
// g2: ["@antv/g2"],
// g6: ["@antv/g6"],
// antv: [
// "@antv/g2",
// "@antv/g6"
// ],
};
return {
...
build: {
rollupOptions: {
output: {
manualChunks: (id) => {
for (const chunk in chunks) {
const names = chunks[chunk];
if (names.some((x) => id.includes(x))) {
return chunk;
}
}
}
}
}
}
}
当 const chunks = { antv: ["@antv/g2", "@antv/g6" ] }
时,一切正常。
当 const chunks = { g2: ["@antv/g2"] }
时,报错
TypeError: Class extends value undefined is not a constructor or null
at Vr (vendor-3SsBoBdA.js:45:1317301)
at g2-LE6X19X4.js:1:3443
at g2-LE6X19X4.js:1:3851
当 const chunks = { g6: ["@antv/g6"] }
时,报错
TypeError: Class extends value undefined is not a constructor or null
at Vr (vendor-DWFphxI8.js:45:1317301)
at g6--5iaV-N9.js:1:78168
at g6--5iaV-N9.js:1:78337
当 const chunks = { g2: ["@antv/g2"], g6: ["@antv/g6"] }
时,报错
TypeError: Cannot read properties of undefined (reading '#f5222d')
at xF (execution-OKOhogkd.js:9:226343)
at rF (execution-OKOhogkd.js:9:217264)
at new bt (execution-OKOhogkd.js:9:212254)
at bt (execution-OKOhogkd.js:9:212236)
at lc (g6-Tg6PtvbS.js:1:301775)
at g6-Tg6PtvbS.js:1:302429
at Array.forEach (<anonymous>)
at g6-Tg6PtvbS.js:1:302403
怀疑 @antv/g2
和 @antv/g6
之间,存在公用的有状态组件,造成分包后状态不一致。
具体原因来不及细查,暂时在此处记录留档。
重现链接
无
重现步骤
无
预期行为
无
平台
无
屏幕截图或视频(可选)
No response
补充说明(可选)
No response