Skip to main content
interlace
Plugin: import-nextRules

prefer-default-export

Prefer a default export if module exports a single name

💼 This rule is enabled in the following configs: recommended, typescript. 💡 This rule is manually fixable by editor suggestions.

Rule Details

A convention: a module that publishes a single value should make it the default export. Which modules qualify depends on target.

  • single (default) and as-needed: report a module whose exports are exactly one value name and no default.
  • always: report a module with any value named export and no default.

Every value name the module publishes counts: inline declarations (also enum, and each name a destructuring declares), export lists (also string names), and export { x } from 'm' re-exports. A default in any spelling (export default, export { x as default }, export { default } from 'm', export * as default from 'm') satisfies the rule. export * from 'm' publishes names the file cannot see, so the count is unknown and single stays silent. Type-only exports and const enum do not count.

❌ Incorrect

// target: single (default)
export const config = { retries: 3 };

export { api } from './api';

✅ Correct

// target: single (default)
const config = { retries: 3 };
export default config;

export const a = 1;
export const b = 2;

export const c = 1;
export * from './more';

Options

[
  {
    "type": "object",
    "properties": {
      "target": {
        "type": "string",
        "enum": [
          "always",
          "single",
          "as-needed"
        ],
        "default": "single",
        "description": "When to enforce default exports: always (any named export and no default), single (exactly one exported name), as-needed (same as single)"
      },
      "ignoreFiles": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "File globs (or path substrings) to ignore"
      },
      "allowNamedExports": {
        "type": "boolean",
        "default": false,
        "description": "Allow named exports without warnings"
      }
    },
    "additionalProperties": false
  }
]
  • target (default single): single or as-needed (the same: one exported name), or always.
  • ignoreFiles (default []): file globs (or path substrings) to skip. A glob matches any run of whole path segments.
  • allowNamedExports (default false): turn the rule off for every file.

When Not To Use It

When your codebase prefers named exports (see no-default-export).

Use this rule

npm install -D oxlint-plugin-import-next
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-import-next"],  "rules": {    "import-next/prefer-default-export": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-import-next'],    rules: {      'import-next/prefer-default-export': 'error',    },  },});

oxlint-plugin-import-next re-exports eslint-plugin-import-next/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.