'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)



Solution 1:[1]

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': {},
    },
  },
}

Solution 2:[2]

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

npm install -D eslint-import-resolver-alias

.eslintrc

  "settings": {
    "import/resolver": {
      "alias": {
        "map": [
          [
            "@",
            "./src"
          ]
        ],
        "extensions": [
          ".js",
          ".ts",
          ".tsx",
          ".jsx",
          ".json"
        ]
      }
    }
  },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Metreci