Prevent assignment to the exports variable in CommonJS modules.
✅ This rule is included in the node logical presets.
In CommonJS modules, assigning directly to the exports variable breaks the reference to module.exports, which means your exports won’t work as expected.
The exports variable is initially a reference to module.exports, but reassigning it creates a new local binding that doesn’t affect the actual module exports.
To export values, always use module.exports directly, or modify properties on exports without reassigning it.
The exports variable is available within a module's file-level scope, and is
assigned the value of module.exports before the module is evaluated.
@since ― v0.1.16
exports= {};
var exports:any
The exports variable is available within a module's file-level scope, and is
assigned the value of module.exports before the module is evaluated.
@since ― v0.1.16
exports= {
foo: number
foo: 1,
bar: number
bar: 2 };
var exports:any
The exports variable is available within a module's file-level scope, and is
assigned the value of module.exports before the module is evaluated.
@since ― v0.1.16
exports=
const somethingElse:any
somethingElse;
var module: NodeJS.Module
A reference to the current module.
@since ― v0.1.16
module.
NodeJS.Module.exports: any
The module.exports object is created by the Module system. Sometimes this is
not acceptable; many want their module to be an instance of some class. To do
this, assign the desired export object to module.exports.
@since ― v0.1.16
exports.
any
foo=1;
var exports:any
The exports variable is available within a module's file-level scope, and is
assigned the value of module.exports before the module is evaluated.
@since ― v0.1.16
exports.
any
bar=2;
var module: NodeJS.Module
A reference to the current module.
@since ― v0.1.16
module.
NodeJS.Module.exports: any
The module.exports object is created by the Module system. Sometimes this is
not acceptable; many want their module to be an instance of some class. To do
this, assign the desired export object to module.exports.
@since ― v0.1.16
exports= {};
var module: NodeJS.Module
A reference to the current module.
@since ― v0.1.16
module.
NodeJS.Module.exports: any
The module.exports object is created by the Module system. Sometimes this is
not acceptable; many want their module to be an instance of some class. To do
this, assign the desired export object to module.exports.
@since ― v0.1.16
exports=
var exports:any
The exports variable is available within a module's file-level scope, and is
assigned the value of module.exports before the module is evaluated.
@since ― v0.1.16
exports= {};
var exports:any
The exports variable is available within a module's file-level scope, and is
assigned the value of module.exports before the module is evaluated.
@since ― v0.1.16
exports=
var module: NodeJS.Module
A reference to the current module.
@since ― v0.1.16
module.
NodeJS.Module.exports: any
The module.exports object is created by the Module system. Sometimes this is
not acceptable; many want their module to be an instance of some class. To do
this, assign the desired export object to module.exports.
If you use an unusual code pattern that intentionally needs to remove the original reference to exports, this rule may not be for you.
However, doing so may make it harder to understand your code or migrate it to the more modern ECMAScript Modules (ESM) syntax.