unplugin-vue-components icon indicating copy to clipboard operation
unplugin-vue-components copied to clipboard

自动引入,引入出现错误

Open PDB6912 opened this issue 2 years ago • 8 comments

//types.ts
export const enum Flow {
  'START_NODE' = 'START_NODE', 
}

//test.vue
impor {Flow} from './types;
import { reactive } from 'vue';
const data = reactive({
  kind : Flow.START_NODE
})

run的时候,auto-imports.d会自动添加 const TART_NODE: typeof import('tdesign-vue-next')['ART_NODE']

终端就会报Internal server error: Failed to resolve import "tdesign-vue-next/es/a-r-t_-n-o-d-e/style" from "src\models\flownodedesigner\flownodedesigner.ts". Does the file exist

看了下https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts,也没明白为什么出现这样的问题,name.match(/^T[A-Z]/  name是怎么获取的

PDB6912 avatar Sep 02 '22 05:09 PDB6912

https://github.com/antfu/unplugin-vue-components/blob/cb8f9325ffdaeb74927d823095a30d2ec9a262a9/src/core/utils.ts#L28

suppose you using a component name with full uppercase. This is out of range.

normally, a compont name like TartNode will be splitted with Uppercase (T/N) then combine with - -> Tart-Node -> toLowercase In your case, TART_NODE will transform to a-r-t_-n-o-d-e

Also, seems TART_NODE is not a tdsign component as well. use your own resolver pls

azaleta avatar Sep 05 '22 14:09 azaleta

It seems to be a bug, please provide a minimum reproduction repo. https://antfu.me/posts/why-reproductions-are-required-zh

sxzz avatar Sep 06 '22 08:09 sxzz

我这个并不是个组件,但是被解析了

PDB6912 avatar Sep 07 '22 03:09 PDB6912

name.match(/^T[A-Z]/

your own code 'TART_NODE' matchs the naming rule(start with T) that will trigger the tdesign process.

azaleta avatar Sep 07 '22 03:09 azaleta

我的code是START_NODE ,是S开头的啊

PDB6912 avatar Sep 23 '22 09:09 PDB6912

'TART_NODE'这个code在我代码里都没出现出现过

PDB6912 avatar Sep 23 '22 09:09 PDB6912

每次出现这个问题,都是我是用类似样式 a.THE 或者 a.STHE,使用对象属性,为什么会被当做引入呢

PDB6912 avatar Sep 23 '22 09:09 PDB6912

const a = { TA: '1' }

let a: any = {} a.STA = '1'

const a = { STA: '1' } a.STA 都会报同样的错误

PDB6912 avatar Sep 23 '22 09:09 PDB6912

unplugin-vue-components 插件只解析模板中的内容,unplugin-auto-import 插件会解析 script 中的内容,你可以尝试移除 auto-import 中配置的 TDesignResolver

Sight-wcg avatar Sep 27 '22 15:09 Sight-wcg

好的,谢谢

PDB6912 avatar Sep 27 '22 16:09 PDB6912