oxc-project/oxc · warning · OxcDiagnostic

Unexpected empty named `import` block.

Error message

Unexpected empty named `import` block.

What it means

Diagnostic from the oxlint rule import/no-empty-named-blocks (suspicious category, autofixable). It fires when a named import block has zero specifiers: `import {} from 'mod'` or `import Default, {} from 'mod'` (including `import type {} from 'mod'` and whitespace-free forms like `import{}from'mod'`). Empty blocks do nothing and are usually debris from accidental deletions or tool-generated code. The rule ships a fix: it deletes the whole statement for the bare case, or removes the `, {}` fragment after a default specifier.

Source

Thrown at crates/oxc_linter/src/rules/import/no_empty_named_blocks.rs:9

use oxc_ast::{AstKind, ast::ImportDeclarationSpecifier};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{AstNode, context::LintContext, rule::Rule};

fn no_empty_named_blocks_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected empty named `import` block.").with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoEmptyNamedBlocks;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Enforces that named import blocks are not empty.
    ///
    /// ### Why is this bad?
    ///
    /// Empty named imports serve no practical purpose and often
    /// result from accidental deletions or tool-generated code.
    ///
    /// ### Examples
    ///
    /// Examples of **incorrect** code for this rule:

View on GitHub (pinned to a3d33dda7c)

Solutions

  1. Run `oxlint --fix` — the statement is auto-deleted (`import {} from 'mod'`) or the empty block is removed (`import Default, {} from 'mod'` → `import Default from 'mod'`)
  2. Delete the empty import statement manually if you cannot run the fixer
  3. Check your codemod/generator if these appear repeatedly — fix it at the source

Example fix

// before
import {} from 'mod';
import Default, {} from 'mod';

// after
import Default from 'mod';
Defensive patterns

Strategy: validation

Validate before calling

// rg -n "^\\s*import\\s+(type\\s+)?\\{\\s*\\}\\s+from" src
// .oxlintrc.json: { "rules": { "import/no-empty-named-blocks": "warn" } }

Prevention

When it happens

Trigger: An ImportDeclaration whose specifiers array exists but is empty (crates/oxc_linter/src/rules/import/no_empty_named_blocks.rs:56), or a lone default specifier followed by `, {}` before `from` (lines 64-89). Bare side-effect imports (`import 'mod'`) are not flagged.

Common situations: Codemods that remove named imports but leave the braces; half-finished refactors where a named import was moved elsewhere; generated files from scaffolding tools.

Related errors


AI-assisted analysis of oxc-project/oxc@a3d33dda7c (2026-08-20). Data as JSON: /api/errors/ef2d8aa6c25e060d. Report an issue: GitHub.