# What are the mandatory files required to create a standard Lightning Web Component?

**Topic:** LWC · **Difficulty:** Medium · **Tags:** LWC, Folder Structure, Metadata

Read it on the site: https://www.forcechallenges.com/interview-questions/what-are-the-mandatory-files-required-to-create-a-standard-lightning-web-component

## Answer

**Basics:** A component lives in a folder under `force-app/main/default/lwc/`, for example `lwc/accountCard/`. The folder name is camelCase and every file inside uses the same base name: `accountCard.html`, `accountCard.js`, `accountCard.js-meta.xml`, and optionally `accountCard.css`. In markup the component is referenced as `<c-account-card>` (namespace `c` for the org's own code, kebab-case for the camelCase name). The HTML is the template, the JS holds the logic, and the XML tells the platform where the component may be used.

**How it works:**
1. The JS file must `export default` a class that extends `LightningElement`.
2. By convention the engine pairs `accountCard.html` with the class and renders it. If no template exists and no `render()` method is defined, the component has no UI. That is legitimate for a pure service or utility module.
3. The meta file is required to deploy the bundle. `isExposed` controls whether it appears in Lightning App Builder, Experience Builder or Flow, and `targets` lists the places it may be dropped.
4. Optional files: `.css` (scoped to the component), `.svg` (custom icon), a `__tests__` folder for Jest, and additional `.js` helper modules imported with `import { x } from './helper'`.

**Advanced / deep dive:** A bundle can hold multiple JS modules, so shared logic can be split into plain ES modules. A "service" bundle with only a JS file and meta file is imported by others with `import { fn } from 'c/utils'`. `targetConfigs` in the meta file define design-time properties for App Builder, mapped to `@api` fields. Flow screens need the `lightning__FlowScreen` target. Components used from record pages can restrict by `objects`. Bundle size and the count of imports affect load time, so keep helper modules lean. Visibility of a component to another namespace follows `isExposed` plus package access rules.

**Code / config example:**
```xml
<!-- accountCard.js-meta.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>61.0</apiVersion>
    <isExposed>true</isExposed>
    <masterLabel>Account Card</masterLabel>
    <targets>
        <target>lightning__RecordPage</target>
        <target>lightning__AppPage</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage">
            <objects><object>Account</object></objects>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>
```
```javascript
// accountCard.js
import { LightningElement } from 'lwc';
export default class AccountCard extends LightningElement {}
```

**Hidden gotchas & must-remember points:**
- HTML is not technically mandatory; JS and meta XML are. The common answer "three mandatory files" is a simplification.
- File and folder names must match exactly and cannot start with a capital letter, contain spaces, hyphens, double underscores, or end with an underscore.
- Without `isExposed` true (or an appropriate target) the component works when nested in other components but never appears in builders.
- A component cannot be used in a page unless its target is declared; forgetting `lightning__RecordPage` is a frequent cause of "component not showing".
- Keep `apiVersion` current; behavior of features like lwc:if depends on it.
- Only one JS class per component file may be the default export.

**Best practice:** Always create bundles with the CLI or VS Code command so names and meta are generated consistently, and keep logic in small helper modules for testability.

---
Source: ForceChallenges · last updated 2026-11-02
