# import/prefer-default-export

> Require a default export in a file that exports a single name

If a file exports one thing, that thing is what the file is for, and a default export says so. Anyone who imports it doesn't have to look up the name.

The rule skips a file if it has a default export, an `export *`, or an exported `type` or `interface`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"import/prefer-default-export" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"import/prefer-default-export" = ["error", {
  target = "single", # "single" or "any"
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
export function formatDate(date) {
  return date.toISOString();
}
```

Not reported:

{/* good */}
```js
export default function formatDate(date) {
  return date.toISOString();
}
```

{/* good */}
```js
export function formatDate(date) {}
export function formatTime(date) {}
```

{/* good */}
```ts
export type UserId = number;
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `target` | `"single"` | `"single"` reports a file with exactly one named export. `"any"` reports every file that has named exports and no default export. |

With `"any"`, this is reported:

{/* bad {"options": [{"target": "any"}]} */}
```js
export function formatDate(date) {}
export function formatTime(date) {}
```

## When not to use it

Named exports keep the same name everywhere, which helps auto-import and renaming. If your project prefers them, use `import/no-default-export` and leave this rule off.
