oxc-project/oxc · error · OxcDiagnostic

Multiple CommonJS exports; consolidate all exports into a si

Error message

Multiple CommonJS exports; consolidate all exports into a single assignment to `module.exports`

What it means

Fires from import/group-exports when a CommonJS module assigns to module.exports (or exports.*) more than once. The rule tracks repeated assignments in run_once and reports the span of the offending assignment with guidance to merge them into a single module.exports object literal.

Source

Thrown at crates/oxc_linter/src/rules/import/group_exports.rs:15

use oxc_ast::{
    AstKind,
    ast::{ImportOrExportKind, MemberExpression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use rustc_hash::FxHashMap;

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

fn group_exports_diagnostic(span: Span, is_commonjs: bool) -> OxcDiagnostic {
    let (msg, help) = if is_commonjs {
        (
            "Multiple CommonJS exports; consolidate all exports into a single assignment to `module.exports`",
            "Combine multiple assignments into a single `module.exports = { ... }` statement",
        )
    } else {
        (
            "Multiple named export declarations; consolidate all named exports into a single export declaration",
            "Use a single export declaration with multiple specifiers: `export { spec1, spec2 }`",
        )
    };
    OxcDiagnostic::warn(msg).with_help(help).with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Reports when named exports are not grouped together in a single export declaration

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Combine all assignments into a single `module.exports = { ... }` statement
  2. Move additional properties into the one object literal instead of mutating exports later
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/import/group_exports.rs:15 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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