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.

Examples

Examples of incorrect code for this rule:

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.

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "no-import-assign": "error"
  }
}
bash
oxlint --deny no-import-assign

References

Released under the MIT License.