tleunen / eslint-import-resolver-babel-module

Custom eslint resolve for babel-plugin-module-resolver
https://github.com/tleunen/babel-plugin-module-resolver
MIT License
248 stars 31 forks source link

Support typescript #99

Open lednhatkhanh opened 5 years ago

lednhatkhanh commented 5 years ago

How can I config it to support typescript? The docs doesn't mention anything about this. Thanks.

GeKorm commented 5 years ago

Have you added the typescript extensions in your babel config? Here's my config for example, which works fine with @babel/preset-typescript

babel
...
[   
  'babel-plugin-module-resolver',
  {
    cwd: 'packagejson',
    root: ['./src'],
    alias: {
      lib: './src/lib'
    },
    extensions: ['.js', '.ts']
  }
]
eslint
"settings": {
  "import/resolver": {
    "node": {
      "paths": ["./src"],
    },
    "babel-module": {}
  }
}
danielo515 commented 4 years ago

I did the other way around, by adding the extensions to te eslintrc config. I think that the example on the README needs to be improved to include some bits of configuration. Right now it only has an empty object and that is kinda useless. Also linking to this documentation will probably be better because it is too hard on the linked one to find useful bits of config.

Robin-Hoodie commented 2 years ago

Bumped into this as well, the secret ingredient is adding the extensions option as mentioned above.

Babel itself doesn't complain when leaving out extensions but this plugin for some reason does. (Assuming @babel/preset-typescript handles this)

The most elegant option is in my opinion to thus add this to the ESLint configuration

// .eslintrc.yml
settings:
  import/resolver:
    babel-module:
      extensions:
        - ".js"
        - ".ts"
        // Add other extensions if needed
vamshiaruru-virgodesigns commented 2 years ago

Sorry for unearthing a very old thread, but this was a life saver. Adding the extensions part fixed my unresolved import errors.