Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellisense for module-alias Package

I am using this npm module (module-alias) https://www.npmjs.com/package/module-alias in my Node project.

To make use of this package you have to set path aliases in the package.json file.

package.json

However, using this package comes with the disadvantage, that intellisense doesn't work anymore.

My question is how to enable intellisense with those path aliases?

like image 614
Flo Avatar asked Dec 09 '18 15:12

Flo


1 Answers

The problem is that you did not register those aliases anywhere with your linter. I would gerenally suggest to use ESLint here (even if you use TypeScript as TSLint will be discontinued in favour of ESLint). My examples will include the TypeScript endings as well. If you definately want to make it work for JavaScript only you can skip the .ts .tsx extentensions in the eslint) So to make intellisense work do this in

.eslintrc.js

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

Note that in this case you will need the import Plugin for ESLint. If you don't already have it install it.

If you are using TypeScript you will also have to make that alias known to your compiler. So add this to your

tsconfig.json

"compilerOptions": {
  "baseUrl": ".",
  "paths": [
    "@/*" : [
      "src/*"
    ]
  ]
}
like image 161
relief.melone Avatar answered Nov 15 '22 02:11

relief.melone