JS.TS.NO.VAR.REQUIRES

Disallows the use of require statements except in import statements

In other words, the use of forms such as var foo = require("foo") are banned. Instead use ES6 style imports or import foo = require("foo") imports.

Rule Details

Examples of code for this rule:

<!--tabs-->

Incorrect

Copy
var foo = require('foo');
const foo = require('foo');
let foo = require('foo');

Correct

Copy
import foo = require('foo');
require('foo');
import foo from 'foo';

Options

Copy
// .eslintrc.json
{
  "rules": {
    "@typescript-eslint/no-var-requires": "error"
  }
}

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/