Skip to content
Advertisement

Vue js error: Component template should contain exactly one root element

I don’t know what the error is, so far I am testing through console log to check for changes after selecting a file (for uploading).

When I run $ npm run watch, i get the following error:

“Webpack is watching the files…

95% emitting

ERROR Failed to compile with 1 errors
19:42:29

error in ./resources/assets/js/components/File.vue

(Emitted value instead of an instance of Error) Vue template syntax error:

Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.

@ ./resources/assets/js/components/AvatarUpload.vue 5:2-181 @ ./resources/assets/js/app.js @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss”

My File.vue is

JavaScript

Any ideas on how to solve this? What is actually the error?

Advertisement

Answer

Note This answer only applies to version 2.x of Vue. Version 3 has lifted this restriction.

You have two root elements in your template.

JavaScript

And you need one.

JavaScript

Essentially in Vue you must have only one root element in your templates.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement