Skip to main content


Disallow require statements except in import statements.

ESLint 配置 中扩展"plugin:@typescript-eslint/recommended" 可启用此规则。

也就是说,禁止使用 var foo = require("foo") 等形式。 请改用 ES6 样式导入或 import foo = require("foo") 导入。

英: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.

module.exports = {
"rules": {
"@typescript-eslint/no-var-requires": "error"
在线运行试试这个规则 ↗


var foo = require('foo');
const foo = require('foo');
let foo = require('foo');
Open in Playground


如果你的项目经常使用较旧的 CommonJS require,那么此规则可能不适用于你。 如果你的项目中只有一部分使用 require,那么你可能会考虑在这些特定情况下使用 ESLint 禁用注释,而不是完全禁用此规则。

英:If your project frequently uses older CommonJS requires, then this rule might not be applicable to you. If only a subset of your project uses requires then you might consider using ESLint disable comments for those specific situations instead of completely disabling this rule.