oxc-project/oxc · error · OxcDiagnostic
Assign arrow function to a variable before exporting as modu
Error message
Assign arrow function to a variable before exporting as module default
What it means
Fires from import/no-anonymous-default-export when the default export is an arrow function expression and allowArrowFunction is false. Unlike the anonymous function/class cases, this message is actionable advice: assign the arrow function to a named variable first.
Source
Thrown at crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:157
ctx.diagnostic(no_anonymous_default_export_diagnostic(
export_decl.span,
"Unexpected default export of anonymous function",
));
}
ExportDefaultDeclarationKind::ClassDeclaration(class_decl)
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",View on GitHub (pinned to e1e7af627c)
Solutions
- Assign the arrow function to a named const, then `export default` that variable
- Enable `allowArrowFunction` to permit arrow default exports
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:157 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/2c40dd69c1b4cff8.
Report an issue: GitHub.