Skip to content

noUnresolvedDefaultImport (JavaScript)

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

Disallow default imports from modules that have no default export.

A default import such as import foo from "./foo.js" only works when ./foo.js has a default export. Otherwise, the import fails when the code runs, or foo ends up undefined, depending on the tool that loads the code. This usually happens when the module only has named exports, for example after a refactor that removed its default export.

This rule only checks modules that use import or export syntax. Imports of CommonJS modules, such as files that assign module.exports, aren’t reported, because those modules have no default export that Biome can check.

Imports of TypeScript declaration files, such as .d.ts files, aren’t reported either. A declaration file often describes a CommonJS module, so its default export can exist even if the file doesn’t declare one.

Imports that Biome can’t resolve to a file aren’t reported.

foo.js
export function foo() {}
bar.js
import foo from "./foo.js";
/bar.js:1:8 lint/nursery/noUnresolvedDefaultImport ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The module ./foo.js has no default export.

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

ℹ This import fails when the code runs, or the imported value is undefined, depending on the tool that loads the code.

ℹ Import one of the named exports of the module instead, or add a default export to the 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
export default function foo() {}
export function bar() {}
baz.js
import foo, { bar } from "./foo.js";
  • To report imports of names that a module doesn’t export, and imports that can’t be resolved, see noUnresolvedImports.