# 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.

## 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,
}]
```

## Examples

Reported:

```js
export function formatDate(date) {
  return date.toISOString().slice(0, 10);
}
```

```js
import { fromatDate } from "./dates.js";
export { parseDate } from "./dates.js";

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

Not reported:

```js
export function formatDate(date) {
  return date.toISOString().slice(0, 10);
}
```

```js
export * from "./dates.js";
```

```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. |

```js
export function formatDate(date) {
  return date.toISOString().slice(0, 10);
}
```

```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.
