Solution: when using Vue 3 script setup, eslint reports the error ‘defineprops’ is not defined
Vue 3’s script setup syntax introduces compiler macros of defineprops
, definemits
, defineexpose
, withdefaults
. However, in some cases, eslint will report an error. The above compiler macro functions are not defined.
This article will introduce two solutions to solve this problem (assuming that your project is initialized with Vue CLI).
Step 1. Check the version of eslint-plugin-Vue
npm list eslint-plugin-vue
If the version is in V8 Above 0.0, jump to step 2, otherwise go directly to the content of step 3.
Step 2. Version is V8.0.0+
Open eslintrc.JS
file and modify it as follows:
env: {
node: true,
// The Follow config only works with eslint-plugin-vue v8.0.0+
"vue/setup-compiler-macros": true,
},
Step 3. Version is V8 Below 0.0
Open eslintrc.JS
file and modify it as follows:
// The Follow configs works with eslint-plugin-vue v7.x.x
globals: {
defineProps: "readonly",
defineEmits: "readonly",
defineExpose: "readonly",
withDefaults: "readonly",
},
If your version of
eslint-plugin-vue
is under V8, I don’t recommended you to upgrade the version,especially you had used a lot of ts dependency.
Read More:
- vue eslint error ‘process‘ is not defined no-undef [How to Solve]
- [Solved] Vue3.0 Error: The component has been registered but not used vue/no-unused-components, Close eslint
- [Solved] Syntax Error: Error: No ESLint configuration found & TypeError: eslint.CLIEngine is not a constructor
- [Solved] Failed to load plugin ‘vue‘ declared in ‘.eslintrc.js‘: createRequire is not a function
- [Solved] Failed to load config “react-app“ to extend from.
- [Solved] Vue Project Error: Arrow function should not return assignment
- [Solved] Eslint Error: Parsing error: x-invalid-end-tag
- How to Solve VUE Error: Mixed spaces and tabs
- [Solved] ✖ 2 problem (1 error, 0 warnings) 2 error and 0 warnings potentially fixable with the`–fix`
- Vscode save Vue format eslint check error [How to Solve]
- [Solved] Vue2.0 Error: Syntax Error: TypeError: eslint.CLIEngine is not a constructor
- Vue3 Error: [vue/no-multiple-template-root] The template root requires exactly one element
- How to Solve Vscode save Vue file eslint error
- [Solved] Errors: 1 http://eslint.org/docs/rules/quotes…elementUI Import Error
- [Solved] Vue Error: error ‘xxx‘ is defined but never used no-unused-vars
- Vue Install less Error: While resolving: [email protected]
- [Solved] ESLint error: Newline required at end of file but not found (eol-last)
- Vue Error: component has been registered but not used [Two Methods to Solve]
- [Solved] error Component name “xxx“ should always be multi-word vue/multi-word-comp
- [Solved] component import error is declared in the statement of components