Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

vite中使用useForm会报错 #29

Closed
1 task done
Kigoal opened this issue Dec 17, 2020 · 2 comments
Closed
1 task done

vite中使用useForm会报错 #29

Kigoal opened this issue Dec 17, 2020 · 2 comments

Comments

@Kigoal
Copy link

Kigoal commented Dec 17, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

2.0.0-rc.4

Environment

MacOS 11.1 / Windows 21H1,Chrome87,Vue 3.0.4,ant-design-vue 2.0.0-rc5

Reproduction link

Edit on CodeSandbox

Steps to reproduce

<template>
  <h1>vite app</h1>
</template>

<script lang="ts">
import { defineComponent, reactive } from 'vue'
import { useForm } from '@ant-design-vue/use'

export default defineComponent({
  name: 'App',
  setup() {
    const modelRef = reactive({})
    const rulesRef = reactive({})
    const { validate, validateInfos } = useForm(modelRef, rulesRef)

    return {
      validate,
      validateInfos
    }
  }
})
</script>

What is expected?

控制台报错:Uncaught SyntaxError: The requested module '/@modules/@babel/runtime/regenerator/index.js' does not provide an export named 'default'

What is actually happening?a

控制台报错:Uncaught SyntaxError: The requested module '/@modules/@babel/runtime/regenerator/index.js' does not provide an export named 'default'


vue-cli中不存在此问题。codesandbox中貌似不能选择vite脚手架,无法提供在线demo
image
image

@Amour1688 Amour1688 transferred this issue from vueComponent/ant-design-vue Dec 17, 2020
@Kigoal Kigoal closed this as completed Dec 18, 2020
@Kigoal Kigoal reopened this Dec 18, 2020
@IMLaoJI
Copy link

IMLaoJI commented Dec 21, 2020

我也遇到了这个问题 有人解决吗

@wangguo1230
Copy link

useForm.ts 引入了lodash和ant-design-vue的依赖

import cloneDeep from 'lodash-es/cloneDeep';
import intersection from 'lodash-es/intersection';
import isEqual from 'lodash-es/isEqual';
import debounce from 'lodash-es/debounce';
import omit from 'lodash-es/omit';
import { FormItemProps as formItemProps } from 'ant-design-vue/es/form/FormItem';
import { validateRules } from 'ant-design-vue/es/form/utils/validateUtil';
import { defaultValidateMessages } from 'ant-design-vue/es/form/utils/messages';
import { allPromiseFinish } from 'ant-design-vue/es/form/utils/asyncUtil';

Vite启动时会报

Deep import "ant-design-vue/es/form/utils/validateUtil" should be avoided because dependency "ant-design-vue" has been pre-optimized

错误。
解决办法是在Vite的optimizeDeps中增加如下依赖:

optimizeDeps: {
    include: [
      // 兼容ant-design useForm
      "lodash-es/cloneDeep",
      "lodash-es/intersection",
      "lodash-es/isEqual",
      "lodash-es/debounce",
      "lodash-es/omit",
      "ant-design-vue/es/form/utils/validateUtil",
      "ant-design-vue/es/form/utils/messages",
      "ant-design-vue/es/form/utils/asyncUtil"
    ],
  }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants