antvis/G6

使用 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


This issue has been closed because it has been outdate for a long time. Please open a new issue if you still need help.

这个 issue 已经被关闭,因为 它已经过期很久了。 如果你仍然需要帮助,请创建一个新的 issue。

posted by github-actions[bot] 6 months ago

Fund this Issue

$0.00
Funded

Pull requests