Skip to main content

no-self-import

Disallow importing the current file from itself.

Targeted pattern scopeโ€‹

This rule resolves relative import/export sources from the current file and reports when a source points back to the same file path.

It checks:

  • ImportDeclaration
  • ExportNamedDeclaration with source
  • ExportAllDeclaration
  • dynamic ImportExpression

What this rule reportsโ€‹

This rule reports relative import/export sources that resolve back to the same file.

Why this rule existsโ€‹

Self-imports create circular module references and are usually accidental. Preventing them avoids confusing runtime and bundler behavior.

โŒ Incorrectโ€‹

// filename: file.ts
import value from "./file";

โœ… Correctโ€‹

// filename: file.ts
import value from "./other-file";

Deprecatedโ€‹

  • Lifecycle: Deprecated and frozen.
  • Deprecated since: v1.0.0
  • Available until: v2.0.0
  • Use instead: import/no-self-import

Behavior and migration notesโ€‹

This rule is deprecated in favor of import/no-self-import from eslint-plugin-import.

Plan migration by enabling the replacement rule, fixing violations, then removing etc-misc/no-self-import.

Optionsโ€‹

This rule has no options.

Statusโ€‹

Use the Deprecated section above for lifecycle details.

Additional examplesโ€‹

// filename: src/utils/math.ts
export * from "./math";
// โŒ reported (self re-export)

// filename: src/utils/math.ts
export * from "./format";
// โœ… valid

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-self-import": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your build tooling intentionally supports self-import patterns.

Package documentationโ€‹

Rule catalog ID: R039

Further readingโ€‹

Adoption resourcesโ€‹

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.