# import/first

> Require all imports to come before every other statement in the file

Imports are hoisted. The imported modules load and run before any line of the file that imports them, no matter where the `import` is written. An import below other code looks like it runs later, but it doesn't.

Directives such as `"use client"` can come before the imports.

`--fix` moves the imports to the top, after the ones that are already there.

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

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
# "absolute-first" or "disable-absolute-first"
"import/first" = ["error", "disable-absolute-first"]
```

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

## Examples

Reported:

{/* bad */}
```js
import { loadConfig } from "./config.js";

loadConfig(); // runs after "./server.js" has loaded, not before

import { startServer } from "./server.js";

startServer();
```

Not reported:

{/* good */}
```js
"use client";

import { loadConfig } from "./config.js";
import { startServer } from "./server.js";

loadConfig();
startServer();
```

## Options

| Option | What it does |
| --- | --- |
| `"disable-absolute-first"` (default) | Imports can be in any order. |
| `"absolute-first"` | Also report an import of a package, or any path that doesn't start with `.`, after a relative import. |

{/* bad {"options": ["absolute-first"]} */}
```js
import { loadConfig } from "./config.js";
import express from "express";
```

{/* good {"options": ["absolute-first"]} */}
```js
import express from "express";
import { loadConfig } from "./config.js";
```
