After scaffolding a Vue 3 project I noticed an error in my App.vue.
A functional component that renders the matched component for the given path. Components rendered in can also contain its own , which will render components for nested paths.
API Reference
[vue/no-multiple-template-root]
The template root requires exactly one element.eslint-plugin-vue
I tried putting
"vue/no-multiple-template-root": 0
in my .eslintrc.js
But the error remains. How can I get rid of the error? Since in Vue 3 you don't have to have exactly one element in a template.
module.exports = {
root: true,
env: {
node: true
},
extends: [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/typescript/recommended",
"@vue/prettier",
"@vue/prettier/@typescript-eslint"
],
parserOptions: {
ecmaVersion: 2020
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
"vue/no-multiple-template-root": 0
}
};
Vue 3 The template root requires exactly one element.eslint-plugin-vue 26 December, 202026 December, 2020 print [vue/valid-template-root] The template root requires exactly one element.eslint-plugin-vue
Components rendered in can also contain its own , which will render components for nested paths. API Reference [vue/no-multiple-template-root] The template root requires exactly one element.eslint-plugin-vue But the error remains. How can I get rid of the error? Since in Vue 3 you don't have to have exactly one element in a template.
If you don't have any package.json in your project's root directory, vetur can't understand which version of vue.js you're using and assumes it is less then 2.5. If the version is wrong, you will get wrong template validation.
Be descriptive about your question or problem and be sure to include any errors. Single line topics will rarely receive answers and do not just post a screenshot. Be specific about which version of Vue and its related plugins you’re using. Link to any 3rd party libs/plugins that relate to your question.
I ended up turning off Vetur linting. Vetur thinks that it is a Vue 2 project becuase it is in a VS Code workspace.
https://github.com/vuejs/vetur/issues/2299#issuecomment-696015374
You can solve this by doing
F1>Preferences:Open Settings (JSON)
paste
"vetur.validation.template": false,
"vetur.validation.script": false,
"vetur.validation.style": false,
The error occurred with me, because I had not opened the project root in VS Code, but the parent folder, and Vetur thus looked in this for the package.json
.
Here worked with this:
in .eslintrc.js
instead of:
rules: { "vue/no-multiple-template-root": 0 }
try:
rules: {"vue/no-multiple-template-root": "off" }
If you are working on a monorepo and thus the package.json is not at the workspace root, then Vetur by default won't able to find package.json, thus it couldn't figure out the vue version.
In that case, we need to tell Vetur the package.json location
https://vuejs.github.io/vetur/guide/setup.html#advanced
With vue create project
on Vue3, add this to your package.json
file:
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {
"vue/no-multiple-template-root": "off"
}
}
Adding the "rules" eliminates the error as described in the question. No need to change the default vetur settings.
Disable Vetur and use Volar instead. It's now the official recommendation for Vue 3 projects.
From the official migration guide:
It is recommended to use VSCode with our official extension Volar (opens new window), which provides comprehensive IDE support for Vue 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With