Registry /
testing / eslint-import-resolver-typescript
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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
TypeScript Resolver (ESLint Flat Config)
✓ import tsResolver from 'eslint-import-resolver-typescript';
✗ const tsResolver = require('eslint-import-resolver-typescript');
When using ESLint's flat configuration (`eslint.config.js`), the resolver module is imported directly as an ES module and then assigned to the 'typescript' key in the `import/resolver` settings. Ensure your config file is an ES module.
TypeScript Resolver (Legacy .eslintrc)
✓ { 'import/resolver': { 'typescript': true } }
✗ { 'import/resolver': { 'typescript': 'eslint-import-resolver-typescript' } }
For traditional `.eslintrc` configurations (JSON, YAML, or CommonJS), the resolver is specified by its package name as a key under `settings['import/resolver']`. A boolean `true` value or an options object is used; ESLint handles the underlying CommonJS `require` automatically. Directly providing the package name as a string value is incorrect.
TypeScript Resolver with Options
✓ { 'import/resolver': { 'typescript': { 'alwaysTryTypes': true, 'project': './tsconfig.eslint.json' } } }
Options for the resolver can be passed as an object instead of `true`. The `project` option is commonly used to specify the path to your TypeScript configuration file(s) for advanced resolution scenarios.
Demonstrates setting up `eslint-import-resolver-typescript` within ESLint's modern flat configuration to resolve TypeScript module paths, including `tsconfig.json` `paths` mappings, and proper handling of various module extensions. It also illustrates how to configure specific parsers for different file types.
/* eslint.config.js */
import eslintPluginImport from 'eslint-plugin-import';
import tsResolver from 'eslint-import-resolver-typescript';
export default [
{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
// Enable import plugin and set up resolver for TypeScript files
plugins: {
import: eslintPluginImport,
},
settings: {
'import/resolver': {
typescript: tsResolver, // Use the imported resolver module
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.mts', '.cjs', '.cts', '.d.ts'],
},
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx', '.mts', '.cts'],
},
},
rules: {
'import/no-unresolved': 'error', // Ensure module paths resolve correctly
'import/named': 'error',
'import/default': 'error',
'import/namespace': 'error',
'import/order': ['error', { 'newlines-between': 'always' }],
// Add other import rules as needed
},
},
// Add configuration for JavaScript files if necessary
{
files: ['**/*.js', '**/*.jsx', '**/*.mjs', '**/*.cjs'],
plugins: {
import: eslintPluginImport,
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.mts', '.cjs', '.cts', '.d.ts'],
},
},
},
rules: {
'import/no-unresolved': 'error',
},
},
];
/* tsconfig.json (example, typically in project root) */
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"lib": ["ES2020", "DOM"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "Bundler",
"baseUrl": ".", // Required for path mapping
"paths": {
"@components/*": ["./src/components/*"],
"@utils/*": ["./src/utils/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.tsx"]
}
// Example usage in src/app.ts (assuming a component 'Button' and util 'formatDate')
// import { Button } from '@components/button';
// import { formatDate } from '@utils/date';
Errors
Common errors & fixes
ESLint: import/no-unresolved: Unable to resolve path to module '@components/button'.
TypeScript `paths` mapping in `tsconfig.json` is not being correctly picked up, or the resolver is not configured properly in ESLint.
fixVerify that `eslint-import-resolver-typescript` is correctly enabled in your ESLint configuration (`settings['import/resolver'].typescript`). Ensure your `tsconfig.json` file is present in a standard location (e.g., project root) or explicitly specified via the `project` option for the resolver.
ESLint: Parsing error: 'import' and 'export' may only appear with 'sourceType: "module"'.
ESLint is attempting to parse a TypeScript or ES module file using a parser that expects CommonJS, or without the correct `sourceType` configured.
fixInstall `@typescript-eslint/parser` and configure it in your ESLint rules, specifically for `.ts`, `.tsx`, `.mts`, and `.cts` files. Ensure `parserOptions.sourceType: 'module'` is explicitly set for these files in your `eslint.config.js` or `.eslintrc`.
TypeError: Cannot read properties of undefined (reading 'getProgram') or similar errors related to TypeScript program initialization.
This error often indicates that the TypeScript language service could not be correctly initialized, possibly due to an invalid or inaccessible `tsconfig.json` path, or a missing `typescript` dependency.
fixEnsure `typescript` is installed in your project (`npm install typescript`) and that your `tsconfig.json` file is valid and accessible from where ESLint is run. If you use the `project` option for the resolver, confirm the specified path(s) are correct and resolve to valid `tsconfig.json` files.
Audit
Dependencies
eslintrequiredRequired peer dependency for ESLint to function as a linter.
eslint-plugin-importoptionalPrimary peer dependency; this resolver enhances its module resolution capabilities for TypeScript.
eslint-plugin-import-xoptionalAlternative peer dependency; this resolver enhances its module resolution capabilities for TypeScript.