Registry / testing / eslint-plugin-no-relative-import-paths

eslint-plugin-no-relative-import-paths

JSON →
library1.6.1jsnpmunverified

ESLint plugin that enforces absolute import paths, preventing the need to update imports when moving files between folders. Version 1.6.1 supports both legacy ESLint config (.eslintrc) and flat config (eslint.config.js), includes TypeScript types, and offers auto-fix via --fix. Options include allowSameFolder, rootDir, prefix, and allowedDepth for flexible configuration. Unlike similar rules (e.g., import/no-relative-parent-imports), this plugin focuses solely on prohibiting relative imports with fix support.

npm install eslint-plugin-no-relative-import-paths
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-NO-R
E
eslint-plugin-no-relative-import-paths
testingjavascriptv1.6.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export
import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths'
const noRelativeImportPaths = require('eslint-plugin-no-relative-import-paths')
For flat config (ESLint >=9), use default import. For legacy config, use plugins array with string 'no-relative-import-paths'.
rule 'no-relative-import-paths'
rules: { 'no-relative-import-paths/no-relative-import-paths': 'warn' }
rules: { 'no-relative-import-paths': 'warn' }
Rule is namespaced under the plugin. Must include 'no-relative-import-paths/' prefix.
flat config usage
import plugin from 'eslint-plugin-no-relative-import-paths'; export default [{ plugins: { 'no-relative-import-paths': plugin }, rules: { 'no-relative-import-paths/no-relative-import-paths': 'error' } }]
export default [{ plugins: ['no-relative-import-paths'], rules: { 'no-relative-import-paths/no-relative-import-paths': 'error' } }]
Flat config requires plugin object, not string. Available since v1.5.4.

Shows flat config and legacy config setup for the plugin with common options: allowSameFolder, rootDir, and prefix.

// eslint.config.js (ESLint flat config, requires v1.5.4+) import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths'; export default [ { plugins: { 'no-relative-import-paths': noRelativeImportPaths, }, rules: { 'no-relative-import-paths/no-relative-import-paths': [ 'error', { allowSameFolder: true, rootDir: 'src', prefix: '@' } ] } } ]; // .eslintrc.json (legacy config) // { // "plugins": ["no-relative-import-paths"], // "rules": { // "no-relative-import-paths/no-relative-import-paths": [ // "warn", // { "allowSameFolder": true, "rootDir": "src", "prefix": "@" } // ] // } // }
Debug
Known issues
breakingFlat config support requires plugin version >=1.5.4 and ESLint >=9.0.0-0. Using older plugin version with flat config will not work.
fix
Update to eslint-plugin-no-relative-import-paths@1.5.4 or newer: npm install eslint-plugin-no-relative-import-paths@latest
affects: <1.5.4
breakingThe rule is not enabled by default; you must explicitly configure it. Setting the rule to 'off' (0) will disable it entirely.
fix
Set the rule to 'warn' or 'error' in your ESLint config (or 1 or 2 in legacy config).
affects: ALL
deprecatedThe options 'enabled' and 'ignorePureComponents' are not documented in recent versions. 'enabled' is replaced by the standard ESLint severity; 'ignorePureComponents' is likely a mistake (confused with allowSameFolder).
fix
Use severity level (0/1/2) instead of 'enabled'. Use 'allowSameFolder' instead of 'ignorePureComponents'.
affects: ALL
gotchaThe auto-fix may add the rootDir as a prefix if rootDir is not set, e.g., fixing '../../components' to 'src/components' instead of 'components'.
fix
Set rootDir option to strip the root directory from the absolute path, e.g., { rootDir: 'src' }.
affects: ALL
breakingIn v1.5.2 and earlier, the prefix option was added but could produce paths with duplicate slashes if rootDir was also set. Now properly handled.
fix
Update to v1.5.3 or newer: npm install eslint-plugin-no-relative-import-paths@1.5.3
affects: >=1.5.0 <1.5.3
gotchaThe rule checks all import/export statements including dynamic imports. Relative imports in require() calls are also flagged.
fix
To allow dynamic or require imports, consider using the 'allowedDepth' option or disable the rule selectively.
affects: ALL
breakingTypeScript types were added in v1.6.0. Using type definitions with older versions may cause TypeScript errors or missing types.
fix
Upgrade to v1.6.0 or newer, or manually define types if needed.
affects: <1.6.0
Errors
Common errors & fixes
ESLint: Failed to load plugin 'no-relative-import-paths' due to an error: Cannot find module 'eslint-plugin-no-relative-import-paths'
Plugin not installed or ESLint cannot resolve it.
fix
Run npm install eslint-plugin-no-relative-import-paths --save-dev
ESLint: Configuration for rule 'no-relative-import-paths/no-relative-import-paths' is invalid: Value "off" is not a valid severity
Using 'off' as a string instead of 0 in legacy config, or mixing flat/legacy patterns.
fix
Use 0 (off), 1 (warn), or 2 (error) as numeric values in legacy config, or 'off'/'warn'/'error' in flat config consistently.
Parsing error: The keyword 'import' is reserved
ESLint not configured for ES modules; using import/export without parserOptions.sourceType: 'module'.
fix
In legacy config: add "parserOptions": { "sourceType": "module" }. In flat config, set languageOptions: { sourceType: 'module' }.
TypeError: Cannot read properties of undefined (reading 'allowSameFolder')
Options object is undefined in older versions (before v1.3.4). The rule expects an options object even if empty.
fix
Update plugin to v1.3.4+: npm install eslint-plugin-no-relative-import-paths@1.3.4
ESLint: Flat config: plugins[n] must be a string or object, got array
Using an array of plugin strings in flat config instead of an object mapping plugin name to plugin object.
fix
Use plugins: { 'no-relative-import-paths': pluginObject } (not an array).
Upgrade
Version history
1.6.1latest on npm
Audit
Dependencies
eslintrequiredPeer dependency - ESLint is required to load the plugin
Agent activity
4 hits · last 30 days
node
4
Resources