oxc-project/oxc · error · OxcDiagnostic
Assign object to a variable before exporting as module defau
Error message
Assign object to a variable before exporting as module default
What it means
Fires from import/no-anonymous-default-export when the default export is an inline object literal and allowObject is false. The message instructs assigning the object to a variable first so the export has an identifiable name in stack traces and tooling.
Source
Thrown at crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:163
if !self.allow_anonymous_class && class_decl.id.is_none() =>
{
ctx.diagnostic(no_anonymous_default_export_diagnostic(
export_decl.span,
"Unexpected default export of anonymous class",
));
}
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",View on GitHub (pinned to e1e7af627c)
Solutions
- Assign the object to a named const, then export default that variable
- Enable `allowObject` if anonymous object 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:163 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/a742ae754e700b6a.
Report an issue: GitHub.