# Validate if import and export paths have an explicit extension (`import-esm/explicit-extension`)

💼 This rule is enabled in the ✅ `recommended` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->

Checks if the import path has an explicit extension.

When `--fix` is used and a path is a directory, `index` will be appended accordingly. Please note that this package does not yet support `exports` field in `package.json`.

## Rule Details

Examples of **incorrect** code for this rule:

```js
import foo from './foo';
```

Examples of **correct** code for this rule:

```js
import foo from './foo.js'
import bar from './bar/index.js'
```

### Options

#### `extension`

The extension to use when auto-fixing. Defaults to `.js`.

```json
{
  "import-esm/explicit-extension": ["error", { "extension": ".mjs" }]
}
```

#### `resolveAliases`

Enable TypeScript path alias resolution from `tsconfig.json`. When enabled, the rule will validate and add explicit extensions to aliased imports (like `@/utils/foo`) defined in your tsconfig paths. Defaults to `false`.

```json
{
  "import-esm/explicit-extension": ["error", {
    "extension": ".js",
    "resolveAliases": true
  }]
}
```

**Example tsconfig.json:**

```json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@utils/*": ["src/utils/*"]
    }
  }
}
```

Examples of **incorrect** code with `resolveAliases: true`:

```js
import foo from '@/foo';
import helper from '@utils/helper';
```

Will be auto-fixed to:

```js
import foo from '@/foo.js';
import helper from '@utils/helper.js';
```

**Note:** This feature requires a valid `tsconfig.json` file in your project with `compilerOptions.paths` configured. The alias paths must resolve to actual files that exist in your project.
