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.