oxc-project/oxc · warning · OxcDiagnostic
Assign array to a variable before exporting as module defaul
Error message
Assign array to a variable before exporting as module default
What it means
Diagnostic from the oxlint rule import/no-anonymous-default-export (style category). It fires when the default export is an array literal, e.g. `export default []`. Anonymous array exports get no stable identifier, hurting grepability, auto-import, and fast-refresh in some bundlers; `allowArray` defaults to false.
Source
Thrown at crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:181
"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(_)))
{
ctx.diagnostic(no_anonymous_default_export_diagnostic(
export_decl.span,
"Assign literal to a variable before exporting as module default",
));
}
}
}
}
}
#[test]View on GitHub (pinned to e1e7af627c)
Solutions
- Assign the array to a named constant first: `const ROUTES = []; export default ROUTES;`
- Enable the option if array defaults are fine: `["warn", { "allowArray": true }]`
- Suppress the single occurrence with a disable comment if the file is generated or intentional
Example fix
// before export default ["react", "vue", "svelte"]; // after const SUPPORTED_FRAMEWORKS = ["react", "vue", "svelte"]; export default SUPPORTED_FRAMEWORKS;
Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json
{ "rules": { "import/no-anonymous-default-export": ["warn", { "allowArray": true }] } } Prevention
- Default to `const NAME = [...]; export default NAME;` for constant tables
- Record allowArray/allowLiteral decisions in the team lint config once
- Let `oxlint --fix`-able sister rules (e.g. no-duplicates) run in the same commit to keep import blocks clean
When it happens
Trigger: Any `export default [...]` (including the empty array `export default []`) in a file linted with the rule enabled and without `{ "allowArray": true }`. Emitted by the `ExportDefaultDeclarationKind::ArrayExpression(_) if !self.allow_array` arm in crates/oxc_linter/src/rules/import/no_anonymous_default_export.rs:181.
Common situations: Config/constant modules like `export default ["en", "de"]` or route tables; codemods that inline arrays into export statements; teams adopting a strict import-plugin preset (e.g. Airbnb-style) that leaves allowArray off.
Related errors
- Assign instance to a variable before exporting as module def
- Assign literal to a variable before exporting as module defa
- Replace default import with named import.
- Expected '{curr_kind}' syntax before '{prev_kind}' syntax.
- Imports should be sorted alphabetically.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/982f983e6783c414.
Report an issue: GitHub.