Sub topic 7
The Configuration File
This chapter covers js-meta.xml, the one file in a Lightning web component bundle that Salesforce requires and that contains no markup or behavior. It assumes you know the bundle layout and naming rules from earlier chapters, can read basic XML, and have used the Salesforce CLI to deploy metadata. Targets and per-target properties get a deeper treatment in the next chapter, so here they appear only as part of the file's overall shape.
What the configuration file does
The HTML, JavaScript and CSS files describe what a component looks like and how it behaves. The configuration file describes how Salesforce treats the component as metadata. It answers questions the other files cannot:
- Which API version should the platform use to run this component?
- Is the component visible to tools such as Lightning App Builder, or is it only usable from other components?
- On which kinds of pages can an admin place it?
- Which values can an admin set in the builder?
Salesforce reads this file at deploy time. If it is missing, the deploy fails, because the bundle is not valid metadata without it. The component's code can be perfect and still never reach the org.
File name and location
The file sits at the root of the bundle. Its name is the bundle name followed by .js-meta.xml.
force-app/main/default/lwc/
└── greetingCard/
├── greetingCard.html
├── greetingCard.js
└── greetingCard.js-meta.xmlTwo points about the name catch people out:
- The base name must match the folder name exactly, including capitalization.
greetingcard.js-meta.xmlinside agreetingCardfolder will not be recognized. - The suffix is
.js-meta.xml, not.meta.xmlor-meta.xml. Thejspart marks it as the companion of the JavaScript file.
A complete example
This is the configuration file for the greetingCard component used throughout the tutorial.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Greeting Card</masterLabel>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__AppPage">
<property name="name" type="String" default="World" />
</targetConfig>
</targetConfigs>
</LightningComponentBundle>The root element is LightningComponentBundle, with the Salesforce metadata namespace. The children can appear in any order, though keeping the order above makes files easier to compare in code review.
The elements, one at a time
apiVersion
apiVersion sets the Salesforce API version the component runs against. The value is a decimal such as 60.0. Salesforce uses it to decide which platform behaviors apply to the component. Newer versions can change defaults or retire old behavior, and pinning a version keeps an existing component from changing under you.
The Salesforce CLI writes the current version into new components, so you rarely type it by hand. When you upgrade a component to a newer version, test it, because behavior tied to the version may change.
isExposed
isExposed controls whether the component appears in Lightning App Builder, Experience Builder, and Flow Builder. It is a boolean written as true or false.
true: the component can be offered to admins, subject to the targets you list.false: the component is hidden from builders. Other components can still use it in their own templates.
The default is false. A frequent mistake is to deploy a component, open App Builder, and not find it. The usual cause is that isExposed is false, or that no targets are listed for the page type you are editing.
Most components in a project are building blocks that other components use. Leave those with isExposed set to false, so admins see only the components you intend them to place.
masterLabel and description
masterLabel is the name an admin sees in the builder's component list. Without it, the builder falls back to the component's API name, which is greetingCard here. A readable label such as Greeting Card is friendlier.
description is optional text that appears in the builder as a tooltip or detail. Use it to say what the component is for in one sentence.
<masterLabel>Greeting Card</masterLabel>
<description>Shows a greeting for a configurable name.</description>targets
targets lists the places the component can be used. Each target is a named page type or context, such as lightning__AppPage, lightning__RecordPage or lightning__HomePage. A component with isExposed set to true and no matching target will not appear on that kind of page.
Listing a target is a promise. For example, a component placed on a record page can receive the current record's ID, but only if its JavaScript declares a public recordId property. The configuration file opens the door, and the class must be ready for what comes through it.
targetConfigs
targetConfigs holds settings that apply to one or more targets. Each targetConfig names the targets it applies to in its targets attribute and declares property elements. A property surfaces in the builder as an editable field, and the value the admin enters is passed to the component's public property of the same name.
<targetConfigs>
<targetConfig targets="lightning__AppPage">
<property name="name" type="String" default="World" />
</targetConfig>
</targetConfigs>A property connects the XML to the JavaScript class by name:
import { LightningElement, api } from 'lwc';
export default class GreetingCard extends LightningElement {
@api name = 'World';
}In this example the XML property name matches the @api name field. If the names differ, the builder shows a field, but the value never reaches the component. The property also appears only on the targets listed in that targetConfig. Here, an admin editing a record page will not see the name field, because the config names only lightning__AppPage.
Other elements
A few more elements appear in real projects. They are listed here so you recognize them.
| Element | Purpose |
|---|---|
| `description` | Optional text shown in builders. |
| `masterLabel` | Display name in builders. |
| `runtimeNamespace` | Namespace used at runtime, mainly for packaged components. |
| `capabilities` | Declares extra abilities for specific contexts, such as Experience Cloud. |
You do not need these for a basic component.
How the file connects to the rest of the bundle
The configuration file is read by the platform, not by the component. Your JavaScript cannot read its values. The relationship runs in one direction.
The diagram shows two separate stages. At deploy time, isExposed and targets decide where the component is listed. After an admin places the component, the property values travel into the class through @api fields.
Common errors
Most configuration problems fall into a short list.
- The file is missing or misnamed. The deploy fails, or Salesforce does not treat the folder as a component. Check that the folder name and the base name match.
- The component does not appear in the builder. Check
isExposed, then check that the page type you are editing is intargets. - A property shows in the builder but has no effect. The XML
namedoes not match an@apiproperty in the class, or the types differ. - A property does not show in the builder. The
targetConfigdoes not list the target you are editing, or the property sits outside atargetConfig. - The XML is not well-formed. An unclosed tag or a stray character produces a deploy error that names a line number. Fix the markup and deploy again.
- An old API version causes odd behavior. Behavior tied to the version can differ from the current platform. Raise the version and test.
Checking the file before you deploy
You can catch most mistakes without opening an org. Validate the project with a deploy dry run:
sf project deploy start --source-dir force-app/main/default/lwc/greetingCard --dry-runThe command checks the bundle against the org without saving anything. A malformed XML file, a missing required element or an invalid target name is reported in the output.
Summary of decisions
| Question | Setting |
|---|---|
| Should admins be able to place this component? | `isExposed` = `true` plus at least one target |
| Is it only a building block for other components? | `isExposed` = `false` |
| What should admins call it? | `masterLabel` |
| Where can it go? | `targets` |
| What can admins customize? | `property` inside `targetConfigs` |
Exercise
A developer deploys a component and cannot find it in Lightning App Builder. The XML contains <isExposed>true</isExposed> and a targets list with only lightning__HomePage. The developer is editing a record page. What is wrong, and what is the fix?
Show answer
The component is exposed, but it lists no target for record pages, so the builder does not offer it there. Add <target>lightning__RecordPage</target> to targets and deploy again.
Exercise
The XML declares <property name="username" type="String" /> in a targetConfig, but the class has @api userName;. The admin enters a value in the builder, and the component ignores it. Why, and how do you fix it?
Show answer
The names differ by capitalization, so the builder value is not passed to the class field. Make both names identical, either username in the XML or userName in both places, then deploy again.