Skip to content

duplicates in #imports #2064

Closed
Closed

Description

@orangejuiceext

Describe the bug

Hi there, I just noticed that I'm generating duplicates in the imports-module.d.ts file.

Image

Thanks for a wonderful project! Keep up the awesome work.

Reproduction

The hint is that they all seem to be classes.

#2064 (comment)

Steps to reproduce

No response

System Info

latest wxt

Used Package Manager

bun

Validations

Activity

  1. added
    pending-triage
    on Feb 2, 2026
  2. aklinker1 commented on Feb 6, 2026

    @aklinker1
    Member

    I don't see any duplicates in your screenshot... please copy-paste the actual text into the issue instead of taking a screenshot of your code. That would make it easier for me to find the duplicates.

    But since you didn't include a reproduction, I'm gonna close this. Here's a good blog post about why full reproductions are necessary: https://antfu.me/posts/why-reproductions-are-required

  3. orangejuiceext commented on Feb 6, 2026

    @orangejuiceext
    Author

    @aklinker1 The duplicates in the screenshot are highlighted text. Instead of just closing the issue right away, at least give me the chance to respond. I'm not trying to waste your time.

    "ActivityTrail", "ProviderAdapter", "InjectAdapter", "ItemData"

    In terms of reproduction, do you have a test for export class Foo {}?

  4. aklinker1 commented on Feb 6, 2026

    @aklinker1
    Member

    duplicates in the screenshot are highlighted text

    Haha 🤦 blind, my bad.

    That said, I still would have closed it since you didn't include a reproduction like the issue template requires. Feel free to update the issue description and re-open once you have a reproduction you can share.

    Read through the blog post I shared if you're not sure what a reproduction is.

  5. added
    needs-reproduction
    on Feb 6, 2026
  6. orangejuiceext commented on Feb 6, 2026

    @orangejuiceext
    Author

    I see now that you just depend on unimport. I'll go poking around there. Sorry for the trouble.

  7. aklinker1 commented on Feb 6, 2026

    @aklinker1
    Member

    You're fine. Creating a minimal reproduction might help you narrow down if it's something in your project specifically that's causing the problem, if it's how WXT uses unimport, or if it's an upstream bug of unimport.

  8. orangejuiceext commented on Feb 6, 2026

    @orangejuiceext
    Author

    Quickly adding a console.log and looking at the output, it is super clear where the duplicates are coming from...

    async function getImportsModuleEntry(wxt, unimport) {
      const imports = await unimport.getImports();
      console.log({ imports });
      return {
        path: "types/imports-module.d.ts",
        text: [
          "// Generated by wxt",
          "// Types for the #import virtual module",
          "declare module '#imports' {",
          `  ${toExports(imports, wxt.config.wxtDir, true).replaceAll("\n", "\n  ")}`,
          "}",
          ""
        ].join("\n"),
        tsReference: true
      };
    }
    
      {
          name: 'ProvideAdapter',
          as: 'ProvideAdapter',
          from: '/Users/checkout/oj/OrangeJuice/src/utils/comctx-adapters.ts'
        },
        {
          name: 'ProvideAdapter',
          as: 'ProvideAdapter',
          from: '/Users/checkout/oj/OrangeJuice/src/utils/comctx-adapters.ts',
          type: true,
          declarationType: 'class'
        },
        {
          name: 'InjectAdapter',
          as: 'InjectAdapter',
          from: '/Users/checkout/oj/OrangeJuice/src/utils/comctx-adapters.ts'
        },
        {
          name: 'InjectAdapter',
          as: 'InjectAdapter',
          from: '/Users/checkout/oj/OrangeJuice/src/utils/comctx-adapters.ts',
          type: true,
          declarationType: 'class'
        },
    
  9. orangejuiceext commented on Feb 6, 2026

    @orangejuiceext
    Author

    Do you need me to do more reproduction work or is this enough now?

  10. aklinker1 commented on Feb 6, 2026

    @aklinker1
    Member

    Give me a reproduction

  11. orangejuiceext commented on Feb 6, 2026

    @orangejuiceext
    Author

    export { Foo, Foo } from '../src/components/foo';

    Unzip, bun install, wxt build, see above line at bottom of file.

    duplicates.zip

  12. removed
    needs-reproduction
    pending-triage
    on Feb 7, 2026
  13. aklinker1 commented on Feb 9, 2026

    @aklinker1
    Member

    OK, I can reproduce, it does appear to be a problem with classes. Unimport version:

    $ bun why unimport
    [email protected]
      └─ [email protected] (requires ^3.13.1 || ^4.0.0 || ^5.0.0)
         ├─ dev wxt-react-starter (requires ^0.20.14)
         └─ peer @wxt-dev/[email protected] (requires >=0.19.16)
            └─ dev wxt-react-starter (requires ^1.1.5)
    

    Here's the relevant WXT code:

    async function getImportsModuleEntry(
    wxt: Wxt,
    unimport: Unimport,
    ): Promise<WxtDirFileEntry> {
    const imports = await unimport.getImports();
    return {
    path: 'types/imports-module.d.ts',
    text: [
    '// Generated by wxt',
    '// Types for the #import virtual module',
    "declare module '#imports' {",
    ` ${toExports(imports, wxt.config.wxtDir, true).replaceAll('\n', '\n ')}`,
    '}',
    '',
    ].join('\n'),
    tsReference: true,
    };
    }

    Here's the results of unimport.getImports

    [
        // ...
        {
          name: 'Foo',
          as: 'Foo',
          from: '/Users/aklinker1/Development/local/wxt-issue-2064/src/components/foo.ts'
        },
        {
          name: 'Foo',
          as: 'Foo',
          from: '/Users/aklinker1/Development/local/wxt-issue-2064/src/components/foo.ts',
          type: true,
          declarationType: 'class'
        }
    ]

    It rightly finds 2 declarations of Foo, one class, one type. Next we call toExports, and that is what returns the duplicate identifier -

    "export { Foo, Foo } from '../src/components/foo';"

    If we remove the types flag from toExports, we get this:

    "export { Foo } from '../src/components/foo';"

    Which would be correct if it didn't strip all the other types from the output... So this makes me think it is an upstream issue with unimport, not WXT.

    That said, maybe there's a better, more correct way to generate the #imports module... I'll look for one, and if not, create an issue over on unjs/unimport.

  14. orangejuiceext commented on Feb 9, 2026

    @orangejuiceext
    Author

    Interestingly, in order to reproduce, I had to switch to using the src folder. Just a plain WXT init project doesn't cause this to happen.

  15. aklinker1 commented on Feb 9, 2026

    @aklinker1
    Member

    Created an issue in unimport: unjs/unimport#498

  16. aklinker1 commented on Feb 9, 2026

    @aklinker1
    Member

    Interestingly, in order to reproduce, I had to switch to using the src folder. Just a plain WXT init project doesn't cause this to happen.

    @orangejuiceext I still get the error when I modify your reproduction to remove the src dir.

  17. added
    upstream
    on Feb 9, 2026
  18. aklinker1 commented on May 11, 2026

    @aklinker1
    Member

    Unimport has fixed this, so once it's released, you can upgrade to it.

    unjs/unimport#498

  19. orangejuiceext commented on May 20, 2026

    @orangejuiceext
    Author

    thank you so much @aklinker1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstream

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions