Skip to content
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

vite项目下,安装引入@antv/x6-vue-shape会报错 #1704

Closed
yetingfeng opened this issue Dec 30, 2021 · 13 comments
Closed

vite项目下,安装引入@antv/x6-vue-shape会报错 #1704

yetingfeng opened this issue Dec 30, 2021 · 13 comments
Assignees
Labels
type: discussion 讨论 Usage questions, guidance, and other discussions

Comments

@yetingfeng
Copy link

Describe the bug

只安装@antv/x6正常,安装x6-vue-shape后会报错

button.ts:10 Uncaught TypeError: Cannot read properties of undefined (reading 'ToolItem');

Your Example Website or App

https://codesandbox.io/s/vibrant-mendeleev-vwbux

Steps to Reproduce the Bug or Issue

1、安装@antv/x6-vue-shape
2、import { Graph } from "@antv/x6";
3、报错button.ts:10 Uncaught TypeError: Cannot read properties of undefined (reading 'ToolItem');

Expected behavior

能正常引入

Screenshots or Videos

No response

Platform

  • OS: Windows10
  • Browser: Chrome

Additional context

No response

@x6-bot
Copy link
Contributor

x6-bot bot commented Dec 30, 2021

👋 @yetingfeng

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@NewByVector
Copy link
Contributor

NewByVector commented Dec 30, 2021

vite 问题,这里有解决方案:vitejs/vite#3413 (comment)

@NewByVector NewByVector self-assigned this Dec 30, 2021
@NewByVector NewByVector added the type: discussion 讨论 Usage questions, guidance, and other discussions label Dec 30, 2021
@Hfutsora
Copy link

vite 问题,这里有解决方案:vitejs/vite#3413 (comment)

{
        find: '@antv/x6',
        replacement: '@antv/x6/dist/x6.js'
},

今天试了,replacement: @antv/x6/lib 不起作用,请设置为 @antv/x6/dist/x6.js,否则 build 后会产生错误。

@taomas
Copy link

taomas commented Apr 8, 2022

使用vite preview或者vite build,还是不能正常展示,请问这个问题有解决方案吗。

@Hfutsora
Copy link

Hfutsora commented Apr 8, 2022

确认你的 alias 配置正确,及 vite, esbuild 版本 https://github.com/vitejs/vite/issues/3413#issuecomment-854301330。

@taomas
Copy link

taomas commented Apr 8, 2022

alias 确认配置正确了,dev 情况下可以正常展示了,但是 vite preiview 没办法展示,和 issues 里面出现了一样的问题。

image

@Hfutsora
Copy link

Hfutsora commented Apr 8, 2022

可以看一下我的项目 https://github.com/soraLib/sa-form/blob/main/vite.config.ts 配置,可以作为你的参考

@taomas
Copy link

taomas commented Apr 8, 2022

感谢,你的项目确实可以正常 preview,我参考一下看看~

@taomas
Copy link

taomas commented Apr 11, 2022

我遇到的问题解决了,更新一下解决方案。

alias 正常配置后,只有通过 tsx 文件进行 render 的自定义组件,build 后能正常展示,如果通过 template 来渲染,build 之后则无法正常显示。

例子:

// FlowNode.tsx文件

import '@antv/x6-vue-shape';
// FlowNode.vue 为自定义组件
import FlowNode from './FlowNode.vue';

export const getFlowNode = (data = { name: '示例组件' }) => {
  return {
    shape: 'vue-shape',
    x: 400,
    y: 48,
    width: 180,
    height: 40,
    component: {
     // build后preiview,可被正常渲染
      render: () => {
        return <FlowNode name={data.name} />;
      },
     // 使用template则不能被正常渲染
      // template: `<FlowNode :name="name"></FlowNode>`,
      // data() {
      //   return {
      //     name: '示例组件',
      //     ...data,
      //   };
      // },
      // components: {
      //   FlowNode,
      // },
    },
  };
};

相关 vite.config.ts 的 alias 配置

resolve: {
  alias: [
    {
      find: '@',
      replacement: path.resolve(__dirname, './src'),
    },
    {
      find: '@antv/x6',
      replacement: '@antv/x6/dist/x6.js',
    },
    {
      find: '@antv/x6-vue-shape',
      replacement: '@antv/x6-vue-shape/lib',
    },
  ],
}

@Huauauaa
Copy link

Thanks @taomas

import { h } from 'vue';
import { Graph } from '@antv/x6';
import '@antv/x6-vue-shape';
import GraphNode from './GraphNode.vue';

Graph.registerNode(
    'graph-node',
    {
      inherit: 'vue-shape',
      width: 200,
      height: 50,
      component: {
        render: () => {
          return h(GraphNode);
        },
      },
    },
    true,
  );

@lulei90
Copy link

lulei90 commented Jul 11, 2022

最优解参考: vitejs/vite#3413 (comment)
不用调整reslove参数配置
建议在官方文档常见问题中更新下 此类问题在搭配使用vite中必现 @NewByVector

@NewByVector
Copy link
Contributor

@lulei90 👍 已经加入到常见问题

@x6-bot
Copy link
Contributor

x6-bot bot commented Jul 12, 2023

This thread has been automatically locked because it has not had recent activity.

Please open a new issue for related bugs and link to relevant comments in this thread.

@x6-bot x6-bot bot locked as resolved and limited conversation to collaborators Jul 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: discussion 讨论 Usage questions, guidance, and other discussions
Projects
None yet
Development

No branches or pull requests

6 participants