{"id":19950,"library":"eslint-plugin-strict-dependencies","title":"eslint-plugin-strict-dependencies","description":"ESLint plugin to enforce custom module dependency rules in TypeScript projects. Current stable version is 1.3.33, released under MIT license. It uses tsconfig paths for alias resolution and supports glob patterns, forward matching, and per-rule allow-lists for import sources. Unlike generic import lint rules, it allows granular control over which modules can import from which paths, including member-level restrictions (e.g., disallowing `Suspense` from `react` except in a specific file). It also offers options like `resolveRelativeImport` to convert relative imports to absolute paths for linting, and `excludeTypeImportChecks` to skip type-only imports. The plugin is actively maintained with regular dependency updates but no major feature changes recently.","status":"active","version":"1.3.33","language":"javascript","source_language":"en","source_url":"https://github.com/knowledge-work/eslint-plugin-strict-dependencies","tags":["javascript","eslint","eslintplugin","lint","rule","check","import","module","directory"],"install":[{"cmd":"npm install eslint-plugin-strict-dependencies","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-strict-dependencies","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-strict-dependencies","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency - the plugin requires ESLint to function","package":"eslint","optional":false}],"imports":[{"note":"The plugin is a default export. When using ESM, import default. When using CommonJS, require the entire module.","wrong":"import { strictDependencies } from 'eslint-plugin-strict-dependencies';","symbol":"plugin (default)","correct":"import plugin from 'eslint-plugin-strict-dependencies'; // or require('eslint-plugin-strict-dependencies')"},{"note":"The rule key is 'strict-dependencies/strict-dependencies' (plugin name / rule name). The rule name is repeated.","wrong":"// Incorrect rule name: \"strict-dependencies/rule\" or \"strict-dependencies/strict-dependency\"","symbol":"strict-dependencies rule","correct":"// In .eslintrc: \"strict-dependencies/strict-dependencies\": \"error\""},{"note":"There is currently no TypeScript type export; the plugin is untyped. This import will fail at runtime.","wrong":"import { Options } from 'eslint-plugin-strict-dependencies';","symbol":"TypeScript type for options","correct":"import type { Options } from 'eslint-plugin-strict-dependencies';"}],"quickstart":{"code":"// .eslintrc.js\nmodule.exports = {\n  plugins: ['strict-dependencies'],\n  rules: {\n    'strict-dependencies/strict-dependencies': [\n      'error',\n      [\n        {\n          module: 'src/components/ui',\n          allowReferenceFrom: ['src/components/page'],\n          allowSameModule: true,\n        },\n        {\n          module: 'next/router',\n          allowReferenceFrom: ['src/libs/router.ts'],\n          allowSameModule: false,\n        },\n      ],\n      // optional options\n      // {\n      //   resolveRelativeImport: true,\n      //   pathIndexMap: { '*': 1 }\n      // }\n    ],\n  },\n};\n","lang":"javascript","description":"This shows how to configure the plugin to restrict imports: 'src/components/ui' can only be imported from 'src/components/page', and 'next/router' can only be imported from 'src/libs/router.ts'."},"warnings":[{"fix":"Ensure tsconfig.json exists and has the necessary paths compilerOptions (if using alias resolution).","message":"The plugin requires a tsconfig.json file in the project root. Without it, the rule will not work.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Use the 'pathIndexMap' option to specify which index to use for each key.","message":"The rule uses tsconfig paths for alias resolution, but by default uses index 0 of each path array. If your tsconfig has multiple paths in an array (e.g., ['aaa/*', 'bbb/*']), the plugin may resolve to the wrong alias.","severity":"gotcha","affected_versions":">=1.3.0"},{"fix":"Set the 'resolveRelativeImport' option to true in the rule options to convert relative imports to absolute paths for linting.","message":"Relative imports are not resolved by default; they are excluded from linting. This can cause missed violations where a relative import reaches a disallowed module.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always test your patterns and prefer explicit glob patterns (e.g., 'src/modules/**') to avoid ambiguity.","message":"The 'module' pattern uses glob matching but also supports forward matching (string prefix). This dual behavior may cause unexpected matches if a pattern accidentally matches unintended paths.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Explicitly set 'allowSameModule' to the desired value to avoid breaking changes in future releases.","message":"The 'allowSameModule' option defaults to true in v1.x but may be deprecated in future versions to enforce stricter rules.","severity":"deprecated","affected_versions":">=1.3.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-strict-dependencies --save-dev' or ensure it is in your package.json.","cause":"The plugin is not installed or ESLint cannot resolve it.","error":"Error: Failed to load plugin 'strict-dependencies' declared in '.eslintrc': Cannot find module 'eslint-plugin-strict-dependencies'"},{"fix":"Run 'npm install typescript --save-dev' to add TypeScript as a dev dependency.","cause":"The plugin uses TypeScript internally to parse tsconfig, but TypeScript is not installed.","error":"Error: Cannot find module 'typescript'. Please install 'typescript' in your project."},{"fix":"Create a tsconfig.json file in your project root, even if minimal, e.g., { \"compilerOptions\": {} }.","cause":"The plugin requires tsconfig.json to resolve paths, but the file is missing.","error":"Error: Could not find tsconfig.json. Make sure a tsconfig.json file exists in the project root."},{"fix":"Install and configure @typescript-eslint/parser in your ESLint config: 'parser: \"@typescript-eslint/parser\"'.","cause":"ESLint is not configured to parse TypeScript. The plugin's rule uses TypeScript AST, but the parser is not set to @typescript-eslint/parser.","error":"Parsing error: The keyword 'import' is reserved"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}