Skip to main content

no-relative-parent-import

Disallow relative parent imports such as ".." and "../*".

Targeted pattern scopeโ€‹

This rule reports module sources that traverse to parent directories using patterns like .., ../**, ../../**, and deeper defaults.

It applies to import/export source strings and dynamic import strings.

What this rule reportsโ€‹

This rule reports imports/exports that traverse parent directories. It helps enforce local-only imports or alias-based module boundaries.

Why this rule existsโ€‹

Preventing parent-relative imports helps enforce bounded module layers and reduces coupling across directory boundaries.

โŒ Incorrectโ€‹

import service from "../service";
export * from "../../utils";

โœ… Correctโ€‹

import service from "./service";
import utils from "@/utils";

Deprecatedโ€‹

Behavior and migration notesโ€‹

This rule is deprecated in favor of import/no-relative-parent-imports from eslint-plugin-import.

It reports only and does not provide an autofix.

Optionsโ€‹

type Options = {
allow?: string[];
disallow?: string[];
};

Default disallow patterns include "..", "../**", "../..", "../../**", and deeper parent traversals.

Use allow for specific exceptions:

{
allow: ["../allowed-source"];
}

Statusโ€‹

Use the Deprecated section above for lifecycle details.

Additional examplesโ€‹

// default disallow includes ../** and ../../**
const mod = await import("../shared/mod");
// โŒ reported

import mod from "@/shared/mod";
// โœ… valid when alias paths are allowed by your resolver

ESLint flat config exampleโ€‹

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

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-relative-parent-import": [
"error",
{ allow: ["../allowed-source"] },
],
},
},
];

When not to use itโ€‹

Disable this rule if parent-relative imports are an accepted part of your module layout.

Package documentationโ€‹

Rule catalog ID: R036

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.