{"id":26959,"library":"eslint-plugin-preferred-import","title":"eslint-plugin-preferred-import","description":"ESLint plugin that autofixes relative imports to use TypeScript or JavaScript path aliases. Current stable version is 1.1.1. Released with moderate cadence; supports both ESLint 9 flat config (with typescript-eslint) and legacy ESLint 8 config. Key differentiator: auto-fixable rules that replace relative paths with configured aliases from tsconfig.json (ts-imports) or manual webpack-like alias map (js-imports), rather than just reporting violations. Requires Node >=16 and ships TypeScript types.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/ronparkdev/eslint-plugin-preferred-import","tags":["javascript","eslint","eslintplugin","eslint-plugin","import","relative","modules","autofix","typescript"],"install":[{"cmd":"npm install eslint-plugin-preferred-import","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-preferred-import","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-preferred-import","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: required as the linting framework","package":"eslint","optional":false}],"imports":[{"note":"Default export is an object containing rules; named exports are not available.","wrong":"import * as preferredImport from 'eslint-plugin-preferred-import'","symbol":"default (import preferredImport)","correct":"import preferredImport from 'eslint-plugin-preferred-import'"},{"note":"Plugin name must be the string 'preferred-import' as used in rule names (e.g., preferred-import/ts-imports).","wrong":"plugins: { preferredImport }","symbol":"plugin in flat config","correct":"plugins: { 'preferred-import': preferredImport }"},{"note":"Rules are namespaced under 'preferred-import/'; omitting prefix causes the rule to not be found.","wrong":"rules: { 'ts-imports': 'error' }","symbol":"rule ts-imports","correct":"rules: { 'preferred-import/ts-imports': 'error' }"},{"note":"Require returns the full plugin object; individual rules must be accessed via preferredImport.rules['ts-imports'].","wrong":"const { ts-imports } = require('eslint-plugin-preferred-import')","symbol":"require in CommonJS","correct":"const preferredImport = require('eslint-plugin-preferred-import')"}],"quickstart":{"code":"// eslint.config.mjs\nimport eslint from '@eslint/js';\nimport tseslint from 'typescript-eslint';\nimport preferredImport from 'eslint-plugin-preferred-import';\n\nexport default tseslint.config(\n  eslint.configs.recommended,\n  tseslint.configs.recommendedTypeChecked,\n  {\n    files: ['**/*.{ts,tsx}'],\n    languageOptions: {\n      parserOptions: {\n        projectService: true,\n      },\n    },\n    plugins: { 'preferred-import': preferredImport },\n    rules: {\n      'preferred-import/ts-imports': 'error',\n    },\n  },\n  { ignores: ['**/node_modules/**', '**/dist/**', '**/.next/**', '**/.turbo/**'] },\n);\n","lang":"javascript","description":"Flat ESLint 9 configuration enabling ts-imports rule to autofix relative imports to tsconfig aliases."},"warnings":[{"fix":"Ensure tsconfig has basePath and paths configured; provide project or projectService in parserOptions.","message":"ts-imports rule requires TypeScript project with tsconfig.json containing basePath and paths.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Verify that the alias resolves to the actual file; if not, the import will be incorrect after autofix.","message":"Rule does not correct incorrect import paths, only replaces relative paths with alias paths if alias maps correctly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For ESLint 9, use the flat config import and plugins object; for ESLint 8, use plugins array and overrides.","message":"ESLint 9 requires flat config; plugin v1.1.1 works with both but config format differs significantly.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run npm install eslint-plugin-preferred-import --save-dev.","cause":"Plugin not installed in the project's node_modules.","error":"Failed to load plugin 'preferred-import' declared in 'plugins': Cannot find module 'eslint-plugin-preferred-import'"},{"fix":"Ensure plugin is imported and registered under the key 'preferred-import' (exact string); rules must be 'preferred-import/ts-imports'.","cause":"Rule name is misspelled or plugin not registered correctly in eslint config.","error":"Definition for rule 'preferred-import/ts-imports' was not found"},{"fix":"Use 'error' (string) is allowed? Actually ESLint flat config accepts string; if using @eslint/js, may need to use 'error' or 2. Check ESLint version.","cause":"Using flat config with string severity instead of severity level from @eslint/js.","error":"Configuration for rule 'preferred-import/ts-imports' is invalid: Value \"error\" should be a number or an array."},{"fix":"Replace parserOptions.project with parserOptions.projectService: true in flat config.","cause":"Using older parserOptions.project in typescript-eslint v8+.","error":"Parsing error: parserOptions.project has been deprecated; use projectService instead"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}