Path: blob/main/docs/rules/no-extraneous-dependencies.md
829 views
import/no-extraneous-dependencies: Forbid the use of extraneous packages
Forbid the import of external modules that are not declared in the package.json's dependencies, devDependencies, optionalDependencies, peerDependencies, or bundledDependencies. The closest parent package.json will be used. If no package.json is found, the rule will not lint anything. This behavior can be changed with the rule option packageDir.
Modules have to be installed for this rule to work.
Options
This rule supports the following options:
devDependencies: If set to false, then the rule will show an error when devDependencies are imported. Defaults to true.
optionalDependencies: If set to false, then the rule will show an error when optionalDependencies are imported. Defaults to true.
peerDependencies: If set to false, then the rule will show an error when peerDependencies are imported. Defaults to true.
bundledDependencies: If set to false, then the rule will show an error when bundledDependencies are imported. Defaults to true.
You can set the options like this:
You can also use an array of globs instead of literal booleans:
When using an array of globs, the setting will be set to true (no errors reported) if the name of the file being linted matches a single glob in the array, and false otherwise.
Also there is one more option called packageDir, this option is to specify the path to the folder containing package.json.
If provided as a relative path string, will be computed relative to the current working directory at linter execution time. If this is not ideal (does not work with some editor integrations), consider using __dirname to provide a path relative to your configuration.
It may also be an array of multiple paths, to support monorepos or other novel project folder layouts:
Rule Details
Given the following package.json:
Fail
Pass
When Not To Use It
If you do not have a package.json file in your project.