JS.TS.NO.REQUIRE.IMPORTS

Disallows invocation of 'require()'

Prefer the newer ES6-style imports over require().

Rule Details

Examples of code for this rule:

<!--tabs-->

Incorrect

コピー
var lib = require('lib');
let lib2 = require('lib2');
var lib5 = require('lib5'),
  lib6 = require('lib6');
import lib8 = require('lib8');

Correct

コピー
import { l } from 'lib';
var lib3 = load('not_an_import');
var lib4 = lib2.subImport;
var lib7 = 700;
import lib9 = lib2.anotherSubImport;
import lib10 from 'lib10';

Options

コピー
// .eslintrc.json
{
  "rules": {
    "@typescript-eslint/no-require-imports": "warn"
  }
}

This rule is not configurable.

When Not To Use It

If you don't care about TypeScript module syntax, then you will not need this rule.

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/