import-js/eslint-plugin-import

`no-unused-modules` erroneously flags `as default` exports

Open

#3 216 ouverte le 17 oct. 2025

Voir sur GitHub
 (2 commentaires) (1 réaction) (0 assignés)JavaScript (1 540 forks)batch import
bughelp wanted

Métriques du dépôt

Stars
 (4 946 stars)
Métriques de merge PR
 (Merge moyen 138j 22h) (3 PRs mergées en 30 j)

Description

Issue Description

The no-unused-modules rule incorrectly reports exports as unused when they use the export { X as default } syntax, even when the default export is properly imported and used by other modules.

This appears to be a bug in how the plugin resolves default exports that are created via the re-export syntax rather than inline default export declarations.

Minimal Reproduction

test-export.ts

export function testHandler() {
  return 'result';
}

export { testHandler as default };

test-import.ts

import handler from './test-export';
console.log(handler());

Current behavior: eslint-plugin-import reports export function testHandler in test-export.ts as unused.

Expected behavior: The rule should recognize that:

  1. testHandler is re-exported as the default export
  2. The default export is imported and used in test-import.ts
  3. Therefore, neither the named export nor the re-export as default should be flagged as unused

Configuration

{
  "import/no-unused-modules": ["error", { "unusedExports": true }]
}

Environment

  • eslint-plugin-import version: 2.31.0
  • Node version: 22.13.1
  • npm version: 10.9.2

Guide contributeur