Skip to content

noDuplicateExports (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noDuplicateExports": "error"
}
}
}
}

Disallow exporting the same name more than once.

A module can export each name, including default, only once. Otherwise, JavaScript refuses to load the module, or one of the exports is silently lost.

The rule also checks TypeScript namespaces and declare module blocks, and the names that export * from "..." brings in from other modules.

export const foo = 1;
function bar() {}
export { bar as foo };
code-block.js:3:17 lint/nursery/noDuplicateExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The name foo is exported more than once.

1 │ export const foo = 1;
2 │ function bar() {}
> 3 │ export { bar as foo };
│ ^^^
4 │

ℹ The name is first exported here.

> 1 │ export const foo = 1;
│ ^^^
2 │ function bar() {}
3 │ export { bar as foo };

ℹ Each exported name must be unique. JavaScript refuses to load a module that exports the same name twice, and TypeScript reports an error.

ℹ Remove one of the exports, or give one of them a different name.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const foo = 1;
export { foo };
export { foo };
code-block.js:3:10 lint/nursery/noDuplicateExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The name foo is exported more than once.

1 │ const foo = 1;
2 │ export { foo };
> 3 │ export { foo };
│ ^^^
4 │

ℹ The name is first exported here.

1 │ const foo = 1;
> 2 │ export { foo };
│ ^^^
3 │ export { foo };
4 │

ℹ Each exported name must be unique. JavaScript refuses to load a module that exports the same name twice, and TypeScript reports an error.

ℹ Remove one of the exports, or give one of them a different name.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const foo = 1;
export default function bar() {}
export { foo as default };
code-block.js:3:17 lint/nursery/noDuplicateExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ There is more than one default export.

1 │ const foo = 1;
2 │ export default function bar() {}
> 3 │ export { foo as default };
│ ^^^^^^^
4 │

ℹ The default export is first defined here.

1 │ const foo = 1;
> 2 │ export default function bar() {}
│ ^^^^^^^
3 │ export { foo as default };
4 │

ℹ Each exported name must be unique. JavaScript refuses to load a module that exports the same name twice, and TypeScript reports an error.

ℹ Remove one of the exports, or give one of them a different name.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

export { foo } from "./foo.js";
export { bar as foo } from "./bar.js";
code-block.js:2:17 lint/nursery/noDuplicateExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The name foo is exported more than once.

1 │ export { foo } from "./foo.js";
> 2 │ export { bar as foo } from "./bar.js";
│ ^^^
3 │

ℹ The name is first exported here.

> 1 │ export { foo } from "./foo.js";
│ ^^^
2 │ export { bar as foo } from "./bar.js";
3 │

ℹ Each exported name must be unique. JavaScript refuses to load a module that exports the same name twice, and TypeScript reports an error.

ℹ Remove one of the exports, or give one of them a different name.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const foo = 1;
type Foo = string;
export { foo as Foo };
export type { Foo };
code-block.ts:4:15 lint/nursery/noDuplicateExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The name Foo is exported more than once.

2 │ type Foo = string;
3 │ export { foo as Foo };
> 4 │ export type { Foo };
│ ^^^
5 │

ℹ The name is first exported here.

1 │ const foo = 1;
2 │ type Foo = string;
> 3 │ export { foo as Foo };
│ ^^^
4 │ export type { Foo };
5 │

ℹ Each exported name must be unique. JavaScript refuses to load a module that exports the same name twice, and TypeScript reports an error.

ℹ Remove one of the exports, or give one of them a different name.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

a.js
export const foo = 1;
b.js
export const foo = 2;
index.js
export * from "./a.js";
export * from "./b.js";
/index.js:2:15 lint/nursery/noDuplicateExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The name foo is exported more than once.

1 │ export * from "./a.js";
> 2 │ export * from "./b.js";
│ ^^^^^^^^
3 │

ℹ This module also exports the name.

> 1 │ export * from "./a.js";
│ ^^^^^^^^
2 │ export * from "./b.js";
3 │

ℹ When two export * from statements export the same name from different declarations, the module doesn't export the name at all. Importing it fails, and TypeScript reports an error.

ℹ Replace one of the export * from statements with export { ... } from, listing only the names you need.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

c.js
export const foo = 1;
main.js
export * from "./c.js";
export const foo = 2;
/main.js:1:15 lint/nursery/noDuplicateExports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The name foo is exported more than once.

> 1 │ export * from "./c.js";
│ ^^^^^^^^
2 │ export const foo = 2;
3 │

ℹ This export replaces the name from the module.

1 │ export * from "./c.js";
> 2 │ export const foo = 2;
│ ^^^
3 │

ℹ A name that the module exports itself takes precedence over the same name from export * from, so the name from the other module is never exported.

ℹ Give the module's own export a different name, or remove it to export the name from the other module.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const foo = 1;
export { foo, foo as bar };
export default foo;
export * as utils from "./utils.js";
const shape = { size: 1 };
export { shape as Shape };
export type Shape = { size: number };
export namespace Inner {
export const foo = 2;
}
  • To report declarations that reuse the name of another declaration in the same scope, including exported ones, see noRedeclare.