# no-relative-packages

Rule `import/no-relative-packages`. Forbid importing packages through relative paths.

- Source: import
- Technologies: Imports
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +2.2% last quarter
- Rank: #1109 by reach, #1616 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `import/no-relative-packages` | no | safe | package `eslint-plugin-import` | [docs](https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-relative-packages.md) |

## Code examples

### Incorrect: the rule reports this

```js
/**
 *  in my-project/packages/foo.js
 */

import bar from '../bar'; // Import sibling package using relative path
import entry from '../../entry.js'; // Import from parent package using relative path

/**
 *  in my-project/entry.js
 */

import bar from './packages/bar'; // Import child package using relative path
```

### Correct: the rule accepts this

```js
/**
 *  in my-project/packages/foo.js
 */

import bar from 'bar'; // Import sibling package using package name

/**
 *  in my-project/entry.js
 */

import bar from 'bar'; // Import sibling package using package name
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import importPlugin from "eslint-plugin-import";

export default [
  {
    plugins: { import: importPlugin },
    rules: {
      "import/no-relative-packages": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |

## Related rules

- [import/no-import-module-exports](https://lintradar.dev/rules/import/no-import-module-exports.md): Forbid import statements with CommonJS module.exports.
- [import/prefer-default-export](https://lintradar.dev/rules/import/prefer-default-export.md): Prefer a default export if module exports a single name or multiple names.
- [import/no-dynamic-require](https://lintradar.dev/rules/import/no-dynamic-require.md): Forbid `require()` calls with expressions.
- [import/order](https://lintradar.dev/rules/import/order.md): Enforce a convention in module import order.
- [import/no-useless-path-segments](https://lintradar.dev/rules/import/no-useless-path-segments.md): Forbid unnecessary path segments in import and require statements.
- [import/extensions](https://lintradar.dev/rules/import/extensions.md): Ensure consistent use of file extension within the import path.

---

Web page: https://lintradar.dev/rules/import/no-relative-packages. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
