johvin / eslint-import-resolver-alias

a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias
MIT License
180 stars 10 forks source link

Custom file extensions #4

Closed Tsury closed 6 years ago

Tsury commented 6 years ago

I'm using eslint-import-resolver-alias along with eslint-import-resolver-typescript.

I have the following alias: ["@dpStores", path.resolve(__dirname, './src/stores')]

But have the following eslint error when I try to import a types.tsx file without specifying the extension: image

If I specify the extension it works just fine. Importing files without an extension works fine when not using an alias.

This is my resolver settings in .eslintrc: "settings": { "import/resolver": { "node": true, "eslint-import-resolver-typescript": true, "alias": [ ["@dpStores", path.resolve(__dirname, './src/stores')] ] } }

johvin commented 6 years ago

@Tsury Actually, eslint-import-resolver-alias uses Node.js native package resolution to find a module and does not support custom file extensions now. That's why it works fine when you specify the extension. I'm going to add this new feature recently and hope that will be helpful.

dhlavaty commented 6 years ago

I have same problem with .jsx extensions.

Tsury commented 6 years ago

@johvin Got it, thanks!

johvin commented 6 years ago

Version 1.1.0 is released to support custom file extensions. @Tsury You can try again with the following configuration in your .eslintrc.js file.

"settings": {
  "import/resolver": {
    "alias": {
      "map": [
        ["@dpStores", path.resolve(__dirname, './src/stores')]
      ],
      "extensions": ['.js', '.ts', '.tsx', '.d.ts', '.json']
    }
  }
}

@dhlavaty You can solve your problem with a similar configuration as above, like "extensions": ['.jsx', '.js', '.json']

Tsury commented 6 years ago

@johvin Thanks, confirmed working!

dhlavaty commented 6 years ago

Works. Thank You