Skip to content

eslint/no-restricted-imports Nursery

What it does

This rule allows you to specify imports that you don’t want to use in your application. It applies to static imports only, not dynamic ones.

Why is this bad?

Some imports might not make sense in a particular environment. For example, Node.js’ fs module would not make sense in an environment that didn’t have a file system.

Some modules provide similar or identical functionality, think lodash and underscore. Your project may have standardized on a module. You want to make sure that the other alternatives are not being used as this would unnecessarily bloat the project and provide a higher maintenance cost of two dependencies when one would suffice.

Examples

Examples of incorrect code for this rule:

js
/*eslint no-restricted-imports: ["error", {
    "name": "disallowed-import",
    "message": "Please use 'allowed-import' instead"
}]*/

import foo from "disallowed-import";

Examples of correct code for this rule:

js
/*eslint no-restricted-imports: ["error", {"name": "fs"}]*/

import crypto from "crypto";
export { foo } from "bar";

References

Released under the MIT License.