eslint + typescript + path in tsconfig: ESLint: Unable to resolve path to module '@components/some-module'.(import/no-unresolved)

Timofey Goncharov picture Timofey Goncharov · Jan 20, 2020 · Viewed 9.7k times · Source

I add typescript config for paths (alias):

tsconfig.json

{
  "compilerOptions": {
    "jsx": "react",
    "baseUrl": "src",
    "paths": {
      "@components/*": ["components/*"]
    }
  },
  "exclude": [
    "node_modules",
    "public"
  ]
}

After that I try import somthing like this:

import Header from '@components/header';

And now I get error in eslint: ESLint: Unable to resolve path to module '@components/header'.(import/no-unresolved)

Answer

Timofey Goncharov picture Timofey Goncharov · Jan 20, 2020

I found a solution in this: eslint-import-resolver-typescript

npm i -D eslint-plugin-import @typescript-eslint/parser eslint-import-resolver-typescript

.eslintrc.js

module.exports = {
  'settings': {
    'import/resolver': {
      'typescript': {},
    },
  },
}