# 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`.

## 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"
}]
```

## Examples

Reported:

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

Not reported:

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

```js
export function formatDate(date) {}
export function formatTime(date) {}
```

```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:

```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.
