no-require-imports
Disallow invocation of
require()
.
Prefer the newer ES6-style imports over require()
.
.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/no-require-imports": "error"
}
};
Examples
- ❌ Incorrect
- ✅ Correct
const lib1 = require('lib1');
const { lib2 } = require('lib2');
import lib3 = require('lib3');
Open in Playgroundimport * as lib1 from 'lib1';
import { lib2 } from 'lib2';
import * as lib3 from 'lib3';
Open in PlaygroundOptions
This rule is not configurable.
When Not To Use It
If your project frequently uses older CommonJS require
s, then this rule might not be applicable to you.
If only a subset of your project uses require
s then you might consider using ESLint disable comments for those specific situations instead of completely disabling this rule.