# import/named

> Require each named import to match a named export in the imported file

`import { formatDate } from "./dates"` fails when the module loads if `./dates` has no export with that name. The usual causes are a typo, a rename that missed a file, or braces around something that's really the default export.

The rule reads the imported file and follows its `export * from` lines. It also checks `export { name } from`. It doesn't report anything if the file can't be found, or if it has no `import` or `export` at all, like a CommonJS module. Type-only imports aren't checked.

It reads JavaScript and TypeScript files, including JSX. With an ESLint config it only reads `.js`, `.mjs` and `.cjs` files, unless `settings["import/extensions"]` lists others.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"import/named" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"import/named" = ["error", {
  commonjs = false,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* file "dates.js" */}
```js
export function formatDate(date) {
  return date.toISOString().slice(0, 10);
}
```

{/* bad {"count": 2} */}
```js
import { fromatDate } from "./dates.js";
export { parseDate } from "./dates.js";

console.log(fromatDate(new Date()));
```

Not reported:

{/* file "dates.js" */}
```js
export function formatDate(date) {
  return date.toISOString().slice(0, 10);
}
```

{/* file "index.js" */}
```js
export * from "./dates.js";
```

{/* good */}
```js
import { formatDate } from "./dates.js";
import { formatDate as format } from "./index.js";

console.log(formatDate(new Date()), format(new Date()));
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `commonjs` | `false` | Also check names that are destructured from a `require()` call. |

{/* file "dates.js" */}
```js
export function formatDate(date) {
  return date.toISOString().slice(0, 10);
}
```

{/* bad {"options": [{"commonjs": true}]} */}
```js
const { parseDate } = require("./dates.js");
```

## When not to use it

TypeScript already reports an import of a name that isn't exported. In a type-checked project, this rule doesn't find anything new.
