LWC Error – LWC1079: Expected root tag to be template, found lightning-card

Published by

on


Hi Ohana,

If you are getting this error and unable to find the reason then this article is going to help you.

Error: LWC1079: Expected root tag to be template, found lightning-card

RCA: You have forget to add Root Tag. Like the <html> element is the root element of an HTML page, in LWC every UI component must have an HTML file with the root tag <template>.

Reference: Component HTML file

Sample Code:

<lightning-card title="ContactInformation" icon-name="custom:custom14">
   <div class="slds-m-around_medium">
      <template for:each={contacts} for:item="contact">
         <div key={contact.Id}>
            {contact.Name}, {contact.Title}
         </div>
      </template>
   </div>
</lightning-card>

Above code will give error:

“LWC1079: Expected root tag to be template, found lightning-card”

So, you need to enclose your code with the root tag <template>.

<template>

   <lightning-card title="ContactInformation" icon-name="custom:custom14">
      <div class="slds-m-around_medium">
         <template for:each={contacts} for:item="contact">
            <div key={contact.Id}>
               {contact.Name}, {contact.Title}
            </div>
         </template>
      </div>
   </lightning-card>
</template>