import/no-mutable-exports
Disallow exporting a variable declared with let or var
Also called import-x/no-mutable-exports
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#
example.js1 problem
export let count = 0;Exporting mutable let binding, use const instead.
export function increment() {
count += 1;
}example.js1 problem
let count = 0;Exporting mutable let binding, use const instead.
export { count };example.jsNo problems
let count = 0;
export const getCount = () => count;
export function increment() {
count += 1;
}