noUndeclaredDependencies
Diagnostic Category: lint/correctness/noUndeclaredDependencies
Since: v1.6.0
Description
Section titled DescriptionDisallow the use of dependencies that aren’t specified in the package.json.
Indirect dependencies will trigger the rule because they aren’t declared in the package.json.
This means that if the 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.
The rule ignores imports that are not valid package names.
This includes internal imports that start with # and @/ and imports with a protocol such as node:, bun:, jsr:, https:.
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
Section titled ExamplesInvalid
Section titled Invalidimport "vite";Valid
Section titled Validimport { A } from "./local.js";import assert from "node:assert";How to configure
Section titled How to configure{ "linter": { "rules": { "correctness": { "noUndeclaredDependencies": "error" } } }}