# import/no-self-import

> Disallow a module from importing itself

A file that imports itself is almost always a mistake left over from a rename, a move, or an editor's auto-import. Everything it gets that way is already in scope, and `require()` returns the `exports` object before the file has finished filling it.

The rule resolves each path, so it also catches other spellings of the same file, such as `.` in an `index.js`. It checks `import`, `export .. from`, `import()` and `require()`.

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

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

## Examples

Reported:

{/* bad {"filename": "cart.js"} */}
```js cart.js
import * as cart from "./cart.js";

export function total(items) {
  return items.length;
}

export function print(items) {
  console.log(cart.total(items));
}
```

{/* bad {"filename": "index.js"} */}
```js index.js
const { version } = require("."); // undefined

exports.version = "1.0.0";
```

Not reported:

{/* good {"filename": "cart.js"} */}
```js cart.js
export function total(items) {
  return items.length;
}

export function print(items) {
  console.log(total(items));
}
```
