no-import-assign
Disallow assigning to imported bindings
error by default
An import is a read-only view of what the other module exports. Assigning to it throws a TypeError when the line runs. The members of a namespace import (import * as name) are read-only too.
This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript reports the same mistake.
Configure#
On by default as an error. To turn it off:
bunfig.toml
[lint.rules]
"no-import-assign" = "off" # or "warn"Examples#
example.js5 problems
import config, { retries } from "./config.js";
import * as settings from "./settings.js";
config = {}config is read-only.;
retries += 1retries is read-only.;
settings.debug = trueThe members of settings are read-only.;
delete settings.debugThe members of settings are read-only.;
Object.assign(settings, { debug: true })The members of settings are read-only.;Not reported. The object that a default or a named import points to is an ordinary object, so you can change its properties. To change a variable in another module, call a function that the module exports for that purpose:
example.jsNo problems
import config, { setRetries } from "./config.js";
config.debug = true;
setRetries(3);