Skip to content

toExports with includeType=true creates duplicate identifiers for classes #498

@aklinker1

Description

@aklinker1

Environment

  • Unimport: 5.6.0
  • Bun: 1.3.8
  • Node: 24.7.0

Reproduction

https://github.com/aklinker1/unimport-class-issue-reproduction

Run it via:

bun install
bun index.ts

# or for node versions that support type-stripping
npm install
node index.ts

Both node and bun behave the same.

Describe the bug

The script is very simple: scan a directory and export all it's values and types.

https://github.com/aklinker1/unimport-class-issue-reproduction/blob/3a8db4ca37131833fae589aac5f2afbc9bec81b4/index.ts#L1C1-L11C39

However, this code produces an invalid export:

export { Foo, Foo } from '/path/to/reproduction/src/Foo';

It's trying to import the class value and type separately.

Is this intentional? Does the code need to filter the imports list before passing it into toExports or should toExports handle this case?

Additional context

Originally reported in WXT: wxt-dev/wxt#2064 (comment)

Logs

Imports: [
  {
    name: 'Foo',
    as: 'Foo',
    from: '/path/to/reproduction/utils/Foo.ts'
  },
  {
    name: 'Foo',
    as: 'Foo',
    from: '/path/to/reproduction/utils/Foo.ts',
    type: true,
    declarationType: 'class'
  }
]

Exports:
export { Foo, Foo } from '/path/to/reproduction/utils/Foo';

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions