AphrodyBun GitHub

Runtime docs · Linter · Rules

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:

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

Every option, set to its default:

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

Examples

Reported:

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

Not reported:

export default function formatDate(date) {
  return date.toISOString();
}
export function formatDate(date) {}
export function formatTime(date) {}
export type UserId = number;

Options

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

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.