requireImports
Reports CommonJS require() imports in favor of ES module imports.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
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.
Examples
Section titled “Examples”const lib = require("lib");var utils = require("./utils");const { x, y } = require("lib");import lib = require("lib");import lib from "lib";import * as utils from "./utils";import { x, y } from "lib";import type { SomeType } from "lib";Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noCommonJs - ESLint:
@typescript-eslint/no-require-imports - Oxlint:
typescript/no-require-imports
Made with ❤️🔥 around the world by
the Flint team and contributors.