Skip to content

noUnresolvedImports

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"nursery": {
"noUnresolvedImports": "error"
}
}
}
}

¥Description

导入不存在的导出文件时会发出警告。

¥Warn when importing non-existing exports.

导入不存在的导出会在运行时或构建时导致错误。Biome 可以检测此类不正确的导入并报告错误。

¥Importing a non-existing export is an error at runtime or build time. Biome can detect such incorrect imports and report errors for them.

请注意,如果你使用 TypeScript,则可能不希望使用此规则,因为 TypeScript 已经为你执行了此类检查。

¥Note that if you use TypeScript, you probably don’t want to use this rule, since TypeScript already performs such checks for you.

¥Known Limitations

  • 此规则不验证通过动态 import() 表达式或 CommonJS require() 调用导入的内容。

    ¥This rule does not validate imports through dynamic import() expressions or CommonJS require() calls.

¥Examples

¥Invalid

foo.js
export function foo() {};
bar.js
// Attempt to import symbol with a typo:
import { fooo } from "./foo.js";
/bar.js:2:10 lint/nursery/noUnresolvedImports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The path ./foo.js has no export named fooo.

1 │ // Attempt to import symbol with a typo:
> 2 │ import { fooo } from “./foo.js”;
^^^^
3 │

Make sure that the path is correct and that you’re importing the right symbol.

¥Valid

foo.js
export function foo() {};
bar.js
// Fixed typo:
import { foo } from "./foo.js";

¥Related links