去评论
海欣资源

Vue3出现‘defineProps‘ is not defined报错怎么办

qqchongx
2022/05/02 19:44:21
按照 vue3一步一步的详细讲解配置ESLint 中 vue 官方推荐安装 ESLint 的方式安装 Eslint,结果发现 'defineProps' is not defined 报错,现在来解决这个问题。

环境
    vite 2.7.2
    vue 3.2.25
配置


安装 ESlint 后

定位问题
defineProps 属于 Vue3 的规则校验,需要在 eslint-plugin-vue官方指南中寻找对应配置。


添加对应配置即可
修改配置


结果新出现了一个报错 Environment key "vue/setup-compiler-macros" is unknown

根据提示可知,是当前依赖包 eslint-plugin-vue 中没有 vue/setup-compiler-macros 规则,故需升级 eslint-plugin-vue,当前最新版本是 8.4.0

出现报错,安装最新版本 node 即可解决。


eslint-plugin-vue@8.4.0: The engine “node” is incompatible with this module. Expected version “^12.22.0 || ^14.17.0 || >=16.0.0”. Got "14.15.0"
当安装成功后,Environment key "vue/setup-compiler-macros" is unknown 报错问题解决。