Skip to content

requireImports

Reports CommonJS require() imports in favor of ES module imports.

✅ This rule is included in the ts logical and logicalStrict presets.

ECMAScript Modules (import/export), or “ESM”, are the standard module system in modern JavaScript and TypeScript. They providing better static analysis, tree-shaking, and overall tooling support over other legacy module systems such as legacy CommonJS (CJS) require() calls. For modern projects, it’s generally preferable to use ESM over CJS.

This rule reports on any instances of legacy require() calls.

const lib = require("lib");
var utils = require("./utils");
const { x, y } = require("lib");
import lib = require("lib");

This rule is not configurable.

If you are working in a CommonJS-only environment where ES modules are not supported, you may want to disable this rule. Some legacy Node.js projects or specific tooling may require CommonJS syntax.

Made with ❤️‍🔥 around the world by the Flint team and contributors.