Disallow specific imports (no-restricted-imports)

Imports are an ES6/ES2015 standard for making the functionality of other modules available in your current module. In CommonJS this is implemented through the require() call which makes this ESLint rule roughly equivalent to its CommonJS counterpart no-restricted-modules.

Why would you want to restrict imports?

Rule Details

This rule allows you to specify imports that you don’t want to use in your application.


The syntax to specify restricted modules looks like this:

"no-restricted-imports": ["error", "import1", "import2"]

To restrict the use of all Node.js core imports (via https://github.com/nodejs/node/tree/master/lib):

    "no-restricted-imports": ["error",

The following patterns are considered problems:

/*eslint no-restricted-imports: ["error", "fs"]*/

import fs from 'fs';
/*eslint no-restricted-imports: ["error", "cluster"]*/

import cluster from ' cluster ';

The following patterns are not considered problems:

/*eslint no-restricted-imports: ["error", "fs"]*/

import crypto from 'crypto';

When Not To Use It

Don’t use this rule or don’t include a module in the list for this rule if you want to be able to import a module in your project without an ESLint error or warning.


This rule was introduced in ESLint 2.0.0-alpha-1.