# import/unambiguous

> Require a module to have an `import` or `export` so it cannot be read as a script

A file with no `import` and no `export` is valid both as a script and as a module, and the two run differently. A module is in strict mode, its top-level `this` is `undefined`, and its top-level declarations aren't global. A tool that has to guess from the content can guess wrong.

One `import` or `export` statement settles it. `import()`, `import.meta`, top-level `await` and `require()` don't count.

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

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

## Examples

Reported:

{/* bad */}
```js
function greet(name) {
  console.log(`Hello, ${name}`);
}

greet("Ada");
```

{/* bad */}
```js
const { greet } = await import("./greet.js");

greet("Ada");
```

Not reported:

{/* good */}
```js
export function greet(name) {
  console.log(`Hello, ${name}`);
}
```

If the file has nothing to export, an empty export marks it as a module:

{/* good */}
```js
function greet(name) {
  console.log(`Hello, ${name}`);
}

greet("Ada");

export {};
```

A `.cjs` file is never a module, so it isn't checked:

{/* good {"filename": "greet.cjs"} */}
```js greet.cjs
console.log("Hello, Ada");
```

## When not to use it

If every tool you use decides by the file extension or by `"type"` in `package.json`, the file's content doesn't matter and this rule is noise.
