2

I add typescript config for paths:

{
 //.....

 "moduleResolution": "node",
{
  "baseUrl": "app",
  "paths": {
  "@app/*": ["*"],
  "@folder/*": ["folder/*"],

  //Other paths
},

}

Added configuration to webpack:

  resolve: {
  extensions: [".tsx", ".ts", ".js", ".jsx", ".css", ".json"],
  alias: {
    "@app":path.resolve(__dirname + "../", "app"),
    "@services":path.resolve(__dirname + "../app", "folder")
  },
  modules: [
    "node_modules", path.resolve(process.cwd(), "app")
  ],
  plugins: [
    new TsConfigPathsPlugin({
      configFile: "../tsconfig.json"
    }),
  ],
},

And here is my .eslint file:

"settings": {
"import/resolver": {
  "node": {
    "paths": [
      "app"
    ],
    "extensions": [
      ".ts",
      ".tsx",
      ".jest.tsx",
      ".d.ts"
    ]
  }
}

After that I try import somthing like this:

import {component} from "@folder/component";

Everything is assembled, the compiler generates no errors But I get error in eslint:

ESLint: Unable to resolve path to module '@folder/component'.(import/no-unresolved)

I've been trying to figure this out for the third day The customer does not want to install additional plugins I would be very grateful for your help!

Alina
  • 21
  • 1
  • 2

1 Answers1

6

the node resolver doesn't understand TypeScript paths. So it's specifically looking for a node module called @folder/component - which won't exist.

You can use the typescript resolver for the plugin: https://www.npmjs.com/package/eslint-import-resolver-typescript

Brad Zacher
  • 2,915
  • 18
  • 31