vue3中defienProps无法导入外部props的问题,报[@vue/compiler-sfc] Failed to resolve import source的错误
在 Vue 3 项目开发中,使用 defineProps 导入外部 props 时,报错的解决方案,报错Failed to resolve extends base type
·
vue3中defienProps无法导入外部props的问题,报[@vue/compiler-sfc] Failed to resolve import source的错误
项目场景
在 Vue 3 项目开发中,使用 defineProps 导入外部 props 时,期望代码能够正常编译运行。
问题描述
在 Vue 3.3 版本之后,官方声称解决了 defineProps 导入外部 props 报错的问题。然而,当本人使用 Vue 3.4 版本(高于 3.3)时,依旧出现了报错。完整报错信息如下:
[@vue/compiler-sfc] Failed to resolve extends base type.
If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it, for example:
interface Props extends /* @vue-ignore */ Base {}
Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.
这是vue3仓库的PR链接,解决defineProps导入外部props报错的问题
解决defineProps导入外部props报错的PR链接
原因分析
经过在官方 issues 中查找,
- 发现问题的原因是在部分 Windows 环境下,使用相对路径引入外部 props 会导致上述报错。
- 使用mac无法复现
解决方案
使用绝对路径引入外部 props 即可解决该问题。
更多推荐
所有评论(0)