{"id":19854,"library":"eslint-plugin-no-relative-import-paths","title":"eslint-plugin-no-relative-import-paths","description":"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.","status":"active","version":"1.6.1","language":"javascript","source_language":"en","source_url":"https://github.com/MelvinVermeer/eslint-plugin-no-relative-import-paths","tags":["javascript","typescript"],"install":[{"cmd":"npm install eslint-plugin-no-relative-import-paths","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-no-relative-import-paths","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-no-relative-import-paths","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - ESLint is required to load the plugin","package":"eslint","optional":false}],"imports":[{"note":"For flat config (ESLint >=9), use default import. For legacy config, use plugins array with string 'no-relative-import-paths'.","wrong":"const noRelativeImportPaths = require('eslint-plugin-no-relative-import-paths')","symbol":"default export","correct":"import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths'"},{"note":"Rule is namespaced under the plugin. Must include 'no-relative-import-paths/' prefix.","wrong":"rules: { 'no-relative-import-paths': 'warn' }","symbol":"rule 'no-relative-import-paths'","correct":"rules: { 'no-relative-import-paths/no-relative-import-paths': 'warn' }"},{"note":"Flat config requires plugin object, not string. Available since v1.5.4.","wrong":"export default [{ plugins: ['no-relative-import-paths'], rules: { 'no-relative-import-paths/no-relative-import-paths': 'error' } }]","symbol":"flat config usage","correct":"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' } }]"}],"quickstart":{"code":"// eslint.config.js (ESLint flat config, requires v1.5.4+)\nimport noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths';\n\nexport default [\n  {\n    plugins: {\n      'no-relative-import-paths': noRelativeImportPaths,\n    },\n    rules: {\n      'no-relative-import-paths/no-relative-import-paths': [\n        'error',\n        { allowSameFolder: true, rootDir: 'src', prefix: '@' }\n      ]\n    }\n  }\n];\n\n// .eslintrc.json (legacy config)\n// {\n//   \"plugins\": [\"no-relative-import-paths\"],\n//   \"rules\": {\n//     \"no-relative-import-paths/no-relative-import-paths\": [\n//       \"warn\",\n//       { \"allowSameFolder\": true, \"rootDir\": \"src\", \"prefix\": \"@\" }\n//     ]\n//   }\n// }","lang":"typescript","description":"Shows flat config and legacy config setup for the plugin with common options: allowSameFolder, rootDir, and prefix."},"warnings":[{"fix":"Update to eslint-plugin-no-relative-import-paths@1.5.4 or newer: npm install eslint-plugin-no-relative-import-paths@latest","message":"Flat config support requires plugin version >=1.5.4 and ESLint >=9.0.0-0. Using older plugin version with flat config will not work.","severity":"breaking","affected_versions":"<1.5.4"},{"fix":"Set the rule to 'warn' or 'error' in your ESLint config (or 1 or 2 in legacy config).","message":"The rule is not enabled by default; you must explicitly configure it. Setting the rule to 'off' (0) will disable it entirely.","severity":"breaking","affected_versions":"ALL"},{"fix":"Use severity level (0/1/2) instead of 'enabled'. Use 'allowSameFolder' instead of 'ignorePureComponents'.","message":"The 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).","severity":"deprecated","affected_versions":"ALL"},{"fix":"Set rootDir option to strip the root directory from the absolute path, e.g., { rootDir: 'src' }.","message":"The auto-fix may add the rootDir as a prefix if rootDir is not set, e.g., fixing '../../components' to 'src/components' instead of 'components'.","severity":"gotcha","affected_versions":"ALL"},{"fix":"Update to v1.5.3 or newer: npm install eslint-plugin-no-relative-import-paths@1.5.3","message":"In 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.","severity":"breaking","affected_versions":">=1.5.0 <1.5.3"},{"fix":"To allow dynamic or require imports, consider using the 'allowedDepth' option or disable the rule selectively.","message":"The rule checks all import/export statements including dynamic imports. Relative imports in require() calls are also flagged.","severity":"gotcha","affected_versions":"ALL"},{"fix":"Upgrade to v1.6.0 or newer, or manually define types if needed.","message":"TypeScript types were added in v1.6.0. Using type definitions with older versions may cause TypeScript errors or missing types.","severity":"breaking","affected_versions":"<1.6.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install eslint-plugin-no-relative-import-paths --save-dev","cause":"Plugin not installed or ESLint cannot resolve it.","error":"ESLint: Failed to load plugin 'no-relative-import-paths' due to an error: Cannot find module 'eslint-plugin-no-relative-import-paths'"},{"fix":"Use 0 (off), 1 (warn), or 2 (error) as numeric values in legacy config, or 'off'/'warn'/'error' in flat config consistently.","cause":"Using 'off' as a string instead of 0 in legacy config, or mixing flat/legacy patterns.","error":"ESLint: Configuration for rule 'no-relative-import-paths/no-relative-import-paths' is invalid: Value \"off\" is not a valid severity"},{"fix":"In legacy config: add \"parserOptions\": { \"sourceType\": \"module\" }. In flat config, set languageOptions: { sourceType: 'module' }.","cause":"ESLint not configured for ES modules; using import/export without parserOptions.sourceType: 'module'.","error":"Parsing error: The keyword 'import' is reserved"},{"fix":"Update plugin to v1.3.4+: npm install eslint-plugin-no-relative-import-paths@1.3.4","cause":"Options object is undefined in older versions (before v1.3.4). The rule expects an options object even if empty.","error":"TypeError: Cannot read properties of undefined (reading 'allowSameFolder')","affected_versions":"<1.3.4"},{"fix":"Use plugins: { 'no-relative-import-paths': pluginObject } (not an array).","cause":"Using an array of plugin strings in flat config instead of an object mapping plugin name to plugin object.","error":"ESLint: Flat config: plugins[n] must be a string or object, got array"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}