Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

import/no-mutable-exports

Disallow exporting a variable declared with let or var

An import is a live view of the exported variable. If the module assigns to an exported let, the value changes in every file that imported it, and nothing at the import tells you that. Code that copied the value keeps the old one, and code that reads it again gets the new one.

The variable is reported whether you export it where it's declared or later, with export { count } or export default count.

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"import/no-mutable-exports" = "error" # or "warn"

Examples

Reported:

export let count = 0;

export function increment() {
  count += 1;
}
let count = 0;

export { count };

Not reported:

let count = 0;

export const getCount = () => count;

export function increment() {
  count += 1;
}