oxc-project/oxc · error · OxcDiagnostic

Assign call result to a variable before exporting as module

Error message

Assign call result to a variable before exporting as module default

What it means

Fires from import/no-anonymous-default-export when the default export is the result of a function call (e.g. `export default connect()(Comp)`) and allowCallExpression (default false) disallows it. The message advises binding the result to a variable before exporting.

Source

Thrown at crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:169

            }
            ExportDefaultDeclarationKind::ArrowFunctionExpression(_)
                if !self.allow_arrow_function =>
            {
                ctx.diagnostic(no_anonymous_default_export_diagnostic(
                    export_decl.span,
                    "Assign arrow function to a variable before exporting as module default",
                ));
            }
            ExportDefaultDeclarationKind::ObjectExpression(_) if !self.allow_object => {
                ctx.diagnostic(no_anonymous_default_export_diagnostic(
                    export_decl.span,
                    "Assign object to a variable before exporting as module default",
                ));
            }
            ExportDefaultDeclarationKind::CallExpression(_) if !self.allow_call_expression => {
                ctx.diagnostic(no_anonymous_default_export_diagnostic(
                    export_decl.span,
                    "Assign call result to a variable before exporting as module default",
                ));
            }
            ExportDefaultDeclarationKind::NewExpression(_) if !self.allow_new => {
                ctx.diagnostic(no_anonymous_default_export_diagnostic(
                    export_decl.span,
                    "Assign instance to a variable before exporting as module default",
                ));
            }
            ExportDefaultDeclarationKind::ArrayExpression(_) if !self.allow_array => {
                ctx.diagnostic(no_anonymous_default_export_diagnostic(
                    export_decl.span,
                    "Assign array to a variable before exporting as module default",
                ));
            }
            _ => {
                if let Some(expr) = export_decl.declaration.as_expression()
                    && !self.allow_literal
                    && (expr.is_literal() || matches!(expr, Expression::TemplateLiteral(_)))

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Assign the call result to a named const, then export default that variable
  2. Enable `allowCallExpression` if call-result default exports are acceptable
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:169 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/fae310d8e6ff6146. Report an issue: GitHub.