Skip to content

Deduplication offset when some imports are disabled #505

Closed

Description

@8ctavio

Environment

node: v20.19.1
unimport: v6.0.1

Reproduction

https://stackblitz.com/edit/stackblitz-starters-tzuzsfbw?file=index.js&view=editor

pnpm install && node index.js

See input and output of getImports(); duplicates are not correctly deduplicated.

Describe the bug

The dedupeImports function manages a Set of imports array indexes that need to be removed (deduplicated). However, imports is first filtered to remove disabled imports, which could cause an offset of collected indexes from the original imports array.

For instance, for the imports:

[{
  name: 'disabled',
  from: 'anywhere.js',
  disabled: true,
},{
  name: 'foo',
  from: 'somewhere.js',
},{
  name: 'foo',
  from: 'elsewhere.js',
}]

the index 1 should be removed, but since the filtered array does not have the disabled import, index 0 will be marked for removal, which ultimately causes the disabled import to be removed instead of the duplicated import.

I am planning to submit a PR to fix this.

Additional context

No response

Logs

Duplicated imports "foo", the one from "anywhere.js" has been ignored and "elsewhere.js" is used
[
  { name: 'foo', from: 'somewhere.js', as: 'foo' },
  { name: 'foo', from: 'elsewhere.js', as: 'foo' }
]

Activity

  1. added
    bug
    on Mar 12, 2026
  2. added a commit that references this issue on Mar 16, 2026
    38ae610
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions