import/no-anonymous-default-export

Disallow default exports that have no name

Also called import-x/no-anonymous-default-export

You can't search for a default export that has no name, and each importing file makes up its own name for it. An anonymous function or class also shows up without a useful name in stack traces and dev tools. Give the value a name first, then export it.

Functions, classes, arrow functions, objects, arrays, literals and new expressions are reported. The result of a call, as in export default defineConfig({}), is allowed by default.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"import/no-anonymous-default-export" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
"import/no-anonymous-default-export" = ["error", {
  allowAnonymousFunction = false,
  allowAnonymousClass = false,
  allowArrowFunction = false,
  allowObject = false,
  allowArray = false,
  allowLiteral = false,
  allowNew = false,
  allowCallExpression = true,
}]

Examples#

example.js1 problem
export default function () {
  return "ok";
}
example.js1 problem
export default items => items.length;
example.js1 problem
export default { port: 3000 };
example.jsNo problems
export default function status() {
  return "ok";
}
example.jsNo problems
const config = { port: 3000 };

export default config;
example.jsNo problems
export default defineConfig({ port: 3000 });

Options#

OptionDefaultWhat it allows
allowAnonymousFunctionfalseexport default function () {}
allowAnonymousClassfalseexport default class {}
allowArrowFunctionfalseexport default () => {}
allowObjectfalseexport default { port: 3000 }
allowArrayfalseexport default [1, 2]
allowLiteralfalseexport default 42, strings, template literals, regular expressions, true, null
allowNewfalseexport default new Server()
allowCallExpressiontrueexport default createServer()
example.jswith { "allowObject": true }No problems
export default { port: 3000 };
example.jswith { "allowCallExpression": false }1 problem
export default defineConfig({ port: 3000 });