Skip to content

eslint/no-import-assign Correctness

This rule is turned on by default.

What it does

Disallow assigning to imported bindings

Why is this bad?

The updates of imported bindings by ES Modules cause runtime errors.

Example

javascript
import mod, { named } from "./mod.mjs";
import * as mod_ns from "./mod.mjs";

mod = 1; // ERROR: 'mod' is readonly.
named = 2; // ERROR: 'named' is readonly.
mod_ns.named = 3; // ERROR: The members of 'mod_ns' are readonly.
mod_ns = {}; // ERROR: 'mod_ns' is readonly.
// Can't extend 'mod_ns'
Object.assign(mod_ns, { foo: "foo" }); // ERROR: The members of 'mod_ns' are readonly.

References

Released under the MIT License.