Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 552
Timofey Goncharov Avatar asked Jan 20 '20 14:01

Timofey Goncharov


1 Answers

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': {},
    },
  },
}
like image 122
Timofey Goncharov Avatar answered Oct 17 '22 05:10

Timofey Goncharov