no-commonjs
UnreleasedConfiguration
Rule Details
Disallow CommonJS imports and exports when migrating to ES modules.
The rule reports require() calls with one string literal or a template literal
without substitutions in the module's variable scope. Calls inside functions,
dynamic arguments, and calls with multiple arguments are allowed. It also reports
module.exports and exports.* member access, including reads.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
The rule does not provide automatic fixes or suggestions.
Options
allowRequire
With { "allowRequire": true }, this is allowed:
CommonJS exports are still reported.
allowConditionalRequire
By default, the following calls are allowed. Set
{ "allowConditionalRequire": false } to report them:
Conditional expressions (condition ? a : b) and logical expressions (&&,
||, ??) also qualify. Loop and switch statements do not.
allowPrimitiveModules
With { "allowPrimitiveModules": true }, these assignments are allowed:
Object literal assignments and exports.* are still reported:
The legacy string option "allow-primitive-modules" enables the same behavior.