antvis / antvis/G6

Vue3+Vite项目引入时报错

Open
#7,155 4 comments 0 reactions 0 assignees View on GitHub
waiting for maintainer
Dominant language
TypeScript
Stars
12.3k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

根据官网的教程,通过 `import G6 from @antv/g6` 报错
> Module '"/node_modules/@antv/g6/lib/index"' has no default export

版本号如下
> npm list @antv/g6
frontend/
└── @antv/g6@5.0.47

>╰─❯ npm list vue
frontend/
├─┬ @vitejs/plugin-vue-jsx@3.0.2
│ └── vue@3.4.27 deduped
├─┬ @vitejs/plugin-vue@4.3.3
│ └── vue@3.4.27 deduped
├─┬ @vue/test-utils@2.4.1
│ ├─┬ @vue/server-renderer@3.4.27
│ │ └── vue@3.4.27 deduped
│ └── vue@3.4.27 deduped
├─┬ @vuelidate/core@2.0.3
│ ├─┬ vue-demi@0.13.11
│ │ └── vue@3.4.27 deduped
│ └── vue@3.4.27 deduped
├─┬ @vuelidate/validators@2.0.4
│ ├─┬ vue-demi@0.13.11
│ │ └── vue@3.4.27 deduped
│ └── vue@3.4.27 deduped
├─┬ pinia@2.1.6
│ ├─┬ vue-demi@0.14.5
│ │ └── vue@3.4.27 deduped
│ └── vue@3.4.27 deduped
├─┬ unplugin-vue-components@0.25.1
│ └── vue@3.4.27 deduped
├─┬ vite-plugin-vuetify@1.0.2
│ └─┬ @vuetify/loader-shared@1.7.1
│ └── vue@3.4.27 deduped
├─┬ vue-router@4.2.4
│ └── vue@3.4.27 deduped
├── vue@3.4.27
└─┬ vuetify@3.6.5
└── vue@3.4.27 deduped

之后通过下面的issue暂时修复了。

> **Please update vite to latest version(2.8.x at present)**
>
>
>
> - [node-resolve plugin is covered by vite](https://vite-rollup-plugins.patak.dev/#node-resolve), and you don't need add this plugin
>
>
>
> - [commonjs plugin is included in vite](https://vite-rollup-plugins.patak.dev/#commonjs), you can set operation in [build.commonjsoptions](https://cn.vitejs.dev/config/#build-commonjsoptions)
>
>
>
> But **it can't fix another issue**, I also have the issue [#3284](https://github.com/antvis/G6/issues/3284) when I build my project by vite(rollup).
>
>
>
> If anyone has the same problem, maybe would fix by setting config like this :
>
>
>
> ```
>
> // vite.config.ts
>
>
>
> {
>
> resolve: {
>
> alias: [
>
> {
>
> find: /^@antv\/g6/,
>
> replacement: path.resolve(
>
> __dirname,
>
> './node_modules/@antv/g6/dist/g6.min.js',
>
> ),
>
> },
>
> ]
>
> }
>
> }
>
> ```
>
>
>
> And this could help me solve my production build...
>
>

_Originally posted by @luxferrew in [#2961](https://github.com/antvis/G6/issues/2961#issuecomment-1041016015)_

想问下官方,使用Vue3+Vite,这个bug还没修复吗?

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the default import in a Vue 3 + Vite project using @antv/g6@5.0.47, then inspect the package's lib/index entry and the referenced vite.config.ts alias to understand the production-build workaround. Done means the documented import works and the production build succeeds without the dist/g6.min.js alias workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript, vite
Domain
build-system, data-visualization, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.