Skip to content

noUndeclaredDependencies

诊断类别:lint/correctness/noUndeclaredDependencies

¥Diagnostic Category: lint/correctness/noUndeclaredDependencies

自从:v1.6.0 禁止使用未在 package.json 中指定的依赖。

¥Since: v1.6.0 Disallow the use of dependencies that aren’t specified in the package.json.

间接依赖将触发规则,因为它们未在 package.json 中声明。这意味着如果包 @org/foo 依赖于 lodash,然后你在项目中的某个地方使用 import "lodash",则该规则将触发此导入的诊断。

¥Indirect dependencies will trigger the rule because they aren’t declared in the package.json. This means that if package @org/foo has a dependency on lodash, and then you use import "lodash" somewhere in your project, the rule will trigger a diagnostic for this import.

该规则忽略使用协议(如 node:bun:jsr:https:)的导入。

¥The rule ignores imports using a protocol such as node:, bun:, jsr:, https:.

要确保 Visual Studio Code 在自动导入变量时使用相对导入,你可以将 javascript.preferences.importModuleSpecifier and typescript.preferences.importModuleSpecifier 设置为 relative

¥To ensure that Visual Studio Code uses relative imports when it automatically imports a variable, you may set javascript.preferences.importModuleSpecifier and typescript.preferences.importModuleSpecifier to relative.

¥Examples

¥Invalid

import "vite";

¥Valid

import { A } from "./local.js";
import assert from "node:assert";

¥Related links