Skip to content

noSelfImport (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noSelfImport": "error"
}
}
}
}

Forbid a module from importing itself.

A module that imports itself is almost always the result of a mistake made while refactoring. It creates a circular dependency on the module itself, which can leave the imported value undefined during evaluation and cause some bundlers to emit a warning or fail.

This rule reports both static import statements and dynamic imports such as import() and require() calls that resolve to the file they appear in.

foo.js
import foo from "./foo.js";
/foo.js:1:17 lint/nursery/noSelfImport ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This module imports itself.

> 1 │ import foo from "./foo.js";
^^^^^^^^^^
2 │

A module that imports itself is a circular dependency, which can leave the imported value undefined during evaluation and cause some bundlers to warn or fail.

Remove this import, or update it to point to the intended module.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

bar.js
const bar = require("./bar.js");
/bar.js:1:13 lint/nursery/noSelfImport ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This module imports itself.

> 1 │ const bar = require("./bar.js");
^^^^^^^^^^^^^^^^^^^
2 │

A module that imports itself is a circular dependency, which can leave the imported value undefined during evaluation and cause some bundlers to warn or fail.

Remove this import, or update it to point to the intended module.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

foo.js
import bar from "./bar.js";