import/no-named-export

Disallow named exports, so that a module only has a default export

Also called import-x/no-named-export

Some projects want each file to export one thing, as its default export. This rule reports every other export: export const, export function, export { name }, export * from and, in TypeScript, export type and export interface.

export { name as default } is a default export, so it's allowed.

Configure#

Off by default. To turn it on:

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

Examples#

example.js2 problems
export const taxRate = 0.2;

export function formatPrice(cents) {
  return `$${(cents / 100).toFixed(2)}`;
}
example.ts3 problems
export * from "./prices";
export type Price = number;
export interface Cart {
  total: Price;
}
example.jsNo problems
export default function formatPrice(cents) {
  return `$${(cents / 100).toFixed(2)}`;
}
example.jsNo problems
const formatPrice = cents => `$${(cents / 100).toFixed(2)}`;

export { formatPrice as default };

When not to use it#

This is the opposite of import/no-default-export. With both on, a module can't export anything.