14

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)

2 Answers 2

44

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': {},
    },
  },
}
Sign up to request clarification or add additional context in comments.

2 Comments

I had to add "compilerOptions": { "moduleResolution": "node" } additionally to tsconfig.json in order to ESlint stop complaining when import from node_modules.
Correct answer. Finally after losing 2 hours for this and giving up to just disable warning, I found this simple solution. Thank you
0

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"
        ]
      }
    }
  },

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.