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]
- How to Solveb Vue3 defineProps Error
- [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] Vue2.0 Error: Syntax Error: TypeError: eslint.CLIEngine is not a constructor
- [Solved] Vue item error: Regeneratorruntime is not defined
- [Solved] vite2+vue3 jsx Error: React is not defined
- How to Solve “Vue is not defined” Error
- Ant design vue table Error: h is not defined [How to Solve]
- [Solved] Vue eslint Error: Component name “*****“ should always be multi-word
- [Solved] Vue3 process Error: Uncaught ReferenceError: process is not defined
- ERROR in [eslint] ESLint is not a constructor (How to Solve)
- [Solved] ESLint:TypeError: this.CliEngine is not a constructor
- [Solved] Vue Error: error ‘xxx‘ is defined but never used no-unused-vars
- Vscode save Vue format eslint check error [How to Solve]
- How to Solve Vscode save Vue file eslint error
- [Solved] Vue Project startup error: no eslint configuration found
- [Solved] Vue Error: error: ‘to‘ is defined but never used (no-unused-vars)
- vue error: ‘ev’ is defined but never used (no-unused-vars)
- [Solved] VUE eslint Error: Expected linebreaks to be ‘LF‘ but found ‘CRLF