import/export
Disallow exporting the same name twice, and export * from a file with no named exports
Also called import-x/export
If two files both export format and you re-export both with export *, JavaScript silently leaves format out, and import { format } fails somewhere else. If your own file exports format too, yours wins and the other one is hidden.
The rule reads the file behind each export * and reports every name that's exported more than once. It also reports an export * from a file that has no named exports. That line does nothing, because export * never passes on a default export.
It reads JavaScript and TypeScript files, including JSX. With an ESLint config it only reads .js, .mjs and .cjs files, unless settings["import/extensions"] lists others.
In TypeScript, function overloads are allowed, and so are a type and a value with the same name, and a namespace merged with a function, class or enum.
Configure#
Off by default. To turn it on:
[lint.rules]
"import/export" = "error" # or "warn"Examples#
Reported:
export function format(date) {
return date.toISOString();
}export function format(number) {
return number.toFixed(2);
}export * from "./dates.js";Multiple exports of name format.
export * from "./numbers.js";Multiple exports of name format.export default function log(message) {
console.log(message);
}export * from "./logger.js"No named exports found in module ./logger.js.;const fallback = "en";
export const localeMultiple exports of name locale. = "de";
export { fallback as localeMultiple exports of name locale. };Not reported:
export function format(date) {
return date.toISOString();
}export function format(number) {
return number.toFixed(2);
}export { format as formatDate } from "./dates.js";
export * from "./numbers.js";export default function log(message) {
console.log(message);
}export { default as log } from "./logger.js";export function parse(input: string): number;
export function parse(input: number): number;
export function parse(input: string | number): number {
return Number(input);
}
export namespace parse {
export const radix = 10;
}
export type Level = "info" | "error";
export const Level = { info: "info", error: "error" } as const;