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.

AEconsB0lAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0requi5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dl1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEva53utiAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0requi5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D./uti1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconst <{ sp ansty="le--0:#82AAFF;--1:#3B61">B<0xsp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#82AAFF;--1:#3B61">B<0ysp ansty="le--0:#C792EA;--1:#8844">AE } <= sp ansty="le--0:#82AAFF;--1:#3B61">B0requi5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dl1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEimpo53 liA5<3 sp ansty="le--0:#C792EA;--1:#8844">AErequi5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dl1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>
44AEim3F53 44AE31<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">44AEim36<1B0* spans="tyle--0:#D6DEEB;--1:#40">3443F53 ut44AE31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D./u1<111" spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">44AEim3F53 { x, 44AE31<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">44AEim344AE3F53 { SomeTyp44AE31<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3

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.