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;Named exports are not allowed.
export function formatPrice(cents) {Named exports are not allowed.
return `$${(cents / 100).toFixed(2)}`;
}example.ts3 problems
export * from "./prices";Named exports are not allowed.
export type Price = number;Named exports are not allowed.
export interface Cart {Named exports are not allowed.
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.