# import/no-unresolved

> Require every import to point to a file or package that exists

A misspelled path, a file that moved, or a package that isn't installed only fails when you run or bundle the code. This rule looks up each import on disk and reports the ones it can't find.

Paths resolve the way they do in Bun and TypeScript:

- A path without an extension is tried with the JavaScript and TypeScript extensions and with `.json`, then as a folder with an `index` file.
- `./user.js` also finds `./user.ts`.
- `paths` in your `tsconfig.json` are followed.
- Anything after a `?` is ignored.
- Node.js built-in modules, `bun` and `bun:test` always resolve.
- `import type` and `export type` aren't checked.

{/* 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/no-unresolved" = "error" # or "warn"
```

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"import/no-unresolved" = ["error", {
  esmodule = true,
  commonjs = false,
  amd = false,
  # ignore = <list of strings>,
  caseSensitive = true,
  caseSensitiveStrict = false,
}]
```

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

## Examples

Reported:

{/* file "utils/format.js" */}
```js utils/format.js
export function formatDate() {}
```

{/* bad {"count": 2} */}
```js
import { formatDate } from "./utils/fromat.js";
import leftPad from "a-package-that-is-not-installed";
```

Not reported:

{/* file "utils/format.js" */}
```js utils/format.js
export function formatDate() {}
```

{/* good */}
```js
import fs from "node:fs";
import { formatDate } from "./utils/format.js";
import { formatDate as format } from "./utils/format";
```

{/* file "user.ts" */}
```ts user.ts
export const user = { name: "Ada" };
```

{/* file "logo.svg" */}
```html logo.svg
<svg />
```

{/* good */}
```ts
import { serve } from "bun";
import { test } from "bun:test";
import { user } from "./user";
import { user as sameUser } from "./user.ts";
import logoUrl from "./logo.svg?url";
```

The `import/resolver` setting changes how paths resolve. Two resolvers are supported: `typescript`, which is the default, and `node` with its `extensions` option. With an ESLint config the default is `node`, as in `eslint-plugin-import`. It tries `.mjs`, `.js`, `.json` and `.node`, and only knows the Node.js built-in modules.

```toml bunfig.toml
[lint.settings]
"import/resolver" = "node"
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `esmodule` | `true` | Check `import`, `export .. from` and `import()`. |
| `commonjs` | `false` | Also check `require()`. |
| `amd` | `false` | Also check the dependencies of `define()` and of `require([..])`. |
| `ignore` | `[]` | Regular expressions. A path that matches one of them is skipped. |

`caseSensitive` and `caseSensitiveStrict` are accepted but have no effect.

Use `ignore` for paths that only a bundler understands:

```toml bunfig.toml
[lint.rules]
"import/no-unresolved" = ["error", { ignore = ["^virtual:"] }]
```

{/* good {"options": [{"ignore": ["^virtual:"]}]} */}
```js
import routes from "virtual:routes";
```

## When not to use it

In a TypeScript project the type checker already reports imports it can't find.
